Given two matrices **mat1** and **mat2** of size **N x N** of elements. Given a value **x**. The problem is to count all pairs from both matrices whose sum is equal to **x**.

**INPUT:** The first line consists of an integer T i.e. the number of test cases. The first line of each test case contains Two Integer** N** , **x** denoting the size of the square Matrix. Next **2*N** lines contain **N** integers separated by space.

**OUTPUT: **For each test case Print the count.

**Constraints:**

1<=T<=50

1 <= N <= 50

0 <= X <= 2000

1<= A[i][j] , B[i][j] <= 1000

**Example:**

Input:

1

3 21

1 5 6

8 10 11

15 16 18

2 4 7

9 10 12

13 16 20

Output:

4

Explanation: The pairs are : (1 , 20 ) , (5 , 16 ) , (8 ,13 ) ,( 11 , 10 )

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.

hari32147 | 100 |

AtakanSarıoğlu | 83 |

geetyadav | 82 |

amitpandey19 | 81 |

AdityaRaj9 | 75 |

abducodes | 862 |

harshtyagi36 | 425 |

vamsikrishna55 | 323 |

sandipbhaumik | 321 |

arpit_anshuman | 319 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.