3048: Dragon Ball Super

时间限制:1000 ms 内存限制:128 MB
上传者:
提交:4 通过:1

题目描述

$Dragon\ Ball\ Super$ has finished. As a fan of $Dragon\ Ball$, $Ctr$ couldn't forget any plot of it, especially the fighting scene of $Tournament\ of\ Power$(力量大会). People who participate in the $Tournament\ of\ Power$ will become the teammate with those who come from the same universe, even $Son\ Goku$ and $Frieza$.

There are $n$ people who may participate in the $Tournament\ of\ Power$, these people are numbered from $1$ to $n$. Also there are $m$ relations $(a_{i}, b_{i})$ which means person $a_{i}$ and person $b_{i}$ are come from the same universe.

$Ctr$ defines the $interest\ value$ of the $Tournament\ of\ Power$ is the number of different universes people, participate in $Tournament\ of\ Power$, come from.

Now, $Ctr$ has $q$ queries to ask you, each of which contains two integers: $l, r$. For each query you are required to tell him the $interest\ value$ when people ( $ l, l+1, ... , r$ ) participate in the $Tournament\ of\ Power$. 


输入格式

The first line contains an integer number $T$, the number of test cases.

For each test case :
The first line contains two integer numbers $n, m(1 \leq n, m \leq 10^{5})$, the number of test cases.

The following $m$ lines, each contains two integers $a_{i}, b_{i}(1 \leq a{i}, b_{i} \leq n)$, which means $a_{i}^{th}$ person and $b_{i}^{th}$ person are come from the same universe.

The next line contains an integer number $q$, the number of query.

The following $m$ lines, each contains two integers $l, r(1 \leq l \leq r \leq n)$.

输出格式

For each query print the answer.

输入样例 复制

1
6 3
1 2
3 4
5 6
2
2 5
2 4

输出样例 复制

3
2