#P9828. Noblesse Code
Noblesse Code
Noblesse Code
Problem Description
You will be given noblesse code pairs and queries. In each query, you will be given a pair , you need to figure out how many noblesse code pairs can be transformed from the given pair . Every time you can transform the current pair into or . You can do the transform operation for arbitrary times (or do nothing).
Input
The first line contains a single integer (), the number of test cases. For each test case: The first line of the input contains two integers and (), denoting the number of noblesse code pairs and the number of queries. In the next lines, the -th line contains two integers and (), describing the -th noblesse code pair. In the next lines, the -th line contains two integers and (), describing the pair in the -th query. It is guaranteed that the sum of all is at most , and the sum of all is at most .
Output
For each query, print a single line containing an integer, denoting the number of noblesse code pairs that can be transformed from the given pair. Note that two noblesse code pairs are considered to be different if and only if .
Sample Input
2
3 4
6 9
5 3
1 1
6 3
1 2
2 1
5 3
2 2
7 14
7 14
7 7
7 14
Sample Output
1
0
1
1
2
2
Source
2023“钉耙编程”中国大学生算法设计超级联赛(3)