问题 L: Noblesse Code

内存限制:512 MB 时间限制:10 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:12 通过:3

题目描述

You will be given n noblesse code pairs (a1,b1),(a2,b2),,(an,bn) and q queries. In each query, you will be given a pair (A,B), you need to figure out how many noblesse code pairs can be transformed from the given pair (A,B). Every time you can transform the current pair (A,B) into(A+B,B) or (A,A+B). You can do the transform operation for arbitrary times (or do nothing).

输入格式

The first line contains a single integer T (1T100), the number of test cases. For each test case:

The first line of the input contains two integers n and q (1n,q50,000), denoting the number of noblesse code pairs and the number of queries.

In the next n lines, the i-th line contains two integers ai and bi (1ai,bi1e18), describing the i-th noblesse code pair.

In the next q lines, the i-th line contains two integers A and B (1A,B1e18), describing the pair in the i-th query.

It is guaranteed that the sum of all n is at most 500,000500,000, and the sum of all q is at most 500,000

输出格式

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 (ai,bi),(aj,bj) are considered to be different if and only if ij.

输入样例 复制

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

输出样例 复制

1
0
1
1
2
2

分类标签