Given an array **A** of **N** positive integers. Find the number of pairs of integers whose difference is equal to a given number **K**.

**Note:** (a, b) and (b, a) are considered same. Also, same numbers at different indices are considered different.

**Input: **

The first line of the input contains T denoting the total number of testcases. Then follows the description of testcases. The first line of each testcase contains two space separated positive integers N and K denoting the size of array and the value of K. The second line contains N space separated positive integers denoting the elements of array.

**Output:**

Output the number of pairs having difference equal to K in a separate line.

**Constraints:**

1 <= T <= 100

1 <= N <= 100

1 <= K <= 100

1 <= A_{i} <= 1000

**Example:**

**Input:**

2

5 2

6 4 5 8 7

4 2

1 3 1 8

**Output:**

3

2

**Explanation:**

**Testcase 1:** (6, 4), (5, 7) and (6, 8) are pairs with difference 2.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

sabka_din_aayega | 317 |

maggiiiii | 248 |

thanuvinu94 | 211 |

Savage_19 | 206 |

Anugrah_kumar | 172 |

Bishnu Dev Panda | 803 |

sabka_din_aayega | 628 |

Anugrah_kumar | 562 |

okayboss | 561 |

maggiiiii | 531 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4925 |

Quandray | 4547 |

Login to report an issue on this page.