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.

jhasaurabh312 | 138 |

Aaaaarohiiii | 136 |

Harsha_kunchala | 128 |

tushki | 124 |

RajaRajput | 117 |

ARUN_PUNDIR | 617 |

manishgupta8497 | 607 |

Abhimanyu_kumar | 559 |

KhyatiSoneji | 501 |

Aman___Jain | 496 |

blackshadows | 5335 |

Ibrahim Nash | 5223 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.