Public Judge

pjudge

Limite de temps : 3 s Limite de mémoire : 512 MB Points totaux : 100 Hackable ✓
Statistiques

Given a simple undirected connected graph with $n$ vertices and $m$ edges.

There are $q$ queries. Each query provides two distinct vertices $x$ and $y$. You can start at $x$ and walk along the graph until you reach $y$, with the restriction that you are not allowed to visit $x$ or $y$ except at the start and the end. Find the number of vertices $z$ such that there exists a walk that passes through $z$, including $x$ and $y$. Note that the path does not have to be a simple path; the only restriction is that you cannot visit $x$ and $y$ again after the start and before the end, respectively.

Input

The first line contains a positive integer $T$, representing the number of test cases. The format for each test case is as follows:

  • The first line contains two positive integers $n$ and $m$, representing the number of vertices and edges.
  • The next $m$ lines each contain two positive integers $x$ and $y$, representing an edge between $x$ and $y$.
  • The next line contains a positive integer $q$, representing the number of queries.
  • The next $q$ lines each contain two positive integers $x$ and $y$, representing a query.

Output

For each query, output a single positive integer on a new line, representing the number of reachable vertices.

Examples

Input 1

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

Output 1

2
4
3
3
5

Examples 2~5

See ex_*.in/ex_*.out in the provided files, which correspond to subtasks 2 through 5, respectively.

Constraints

This problem uses bundled testing; you must pass all test cases in a subtask to receive points for that subtask.

For all data, $1\le T\le 1000, 1\le \sum n\le 2\times 10^5, 1\le \sum m \le 5\times 10^5, 1\le \sum q\le 5\times 10^5$.

Subtask ID Special Properties Score
$1$ $1\le T\le 5,n,m,q\le 20$ $10$
$2$ $\sum n\le 1000,\sum m,\sum q\le 2000$ $20$
$3$ $m=n-1$ $20$
$4$ The graph remains connected after removing any single vertex $10$
$5$ No special properties $40$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.