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.

bhatabhi554 | 317 |

hardikJain5 | 306 |

CodeBuddy | 293 |

Akkki111 | 233 |

clone | 230 |

KshatriyaYash | 1932 |

nikhil_sojan | 1374 |

lonecoder | 1236 |

mazumderrohit8 | 1176 |

RemoveTLE | 1144 |

blackshadows | 5327 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4605 |

Quandray | 4444 |

Login to report an issue on this page.