Package for this problem was not updated by the problem writer or Codeforces administration after we’ve upgraded the judging servers. To adjust the time limit constraint, solution execution time will be multiplied by 2. For example, if your solution works for 400 ms on judging servers, then value 800 ms will be displayed and used to determine the verdict.

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

E. Cactus

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputA connected undirected graph is called a vertex cactus, if each vertex of this graph belongs to at most one simple cycle.

A simple cycle in a undirected graph is a sequence of distinct vertices *v*_{1}, *v*_{2}, ..., *v*_{t} (*t* > 2), such that for any *i* (1 ≤ *i* < *t*) exists an edge between vertices *v*_{i} and *v*_{i + 1}, and also exists an edge between vertices *v*_{1} and *v*_{t}.

A simple path in a undirected graph is a sequence of not necessarily distinct vertices *v*_{1}, *v*_{2}, ..., *v*_{t} (*t* > 0), such that for any *i* (1 ≤ *i* < *t*) exists an edge between vertices *v*_{i} and *v*_{i + 1} and furthermore each edge occurs no more than once. We'll say that a simple path *v*_{1}, *v*_{2}, ..., *v*_{t} starts at vertex *v*_{1} and ends at vertex *v*_{t}.

You've got a graph consisting of *n* vertices and *m* edges, that is a vertex cactus. Also, you've got a list of *k* pairs of interesting vertices *x*_{i}, *y*_{i}, for which you want to know the following information — the number of distinct simple paths that start at vertex *x*_{i} and end at vertex *y*_{i}. We will consider two simple paths distinct if the sets of edges of the paths are distinct.

For each pair of interesting vertices count the number of distinct simple paths between them. As this number can be rather large, you should calculate it modulo 1000000007 (10^{9} + 7).

Input

The first line contains two space-separated integers *n*, *m* (2 ≤ *n* ≤ 10^{5}; 1 ≤ *m* ≤ 10^{5}) — the number of vertices and edges in the graph, correspondingly. Next *m* lines contain the description of the edges: the *i*-th line contains two space-separated integers *a*_{i}, *b*_{i} (1 ≤ *a*_{i}, *b*_{i} ≤ *n*) — the indexes of the vertices connected by the *i*-th edge.

The next line contains a single integer *k* (1 ≤ *k* ≤ 10^{5}) — the number of pairs of interesting vertices. Next *k* lines contain the list of pairs of interesting vertices: the *i*-th line contains two space-separated numbers *x*_{i}, *y*_{i} (1 ≤ *x*_{i}, *y*_{i} ≤ *n*; *x*_{i} ≠ *y*_{i}) — the indexes of interesting vertices in the *i*-th pair.

It is guaranteed that the given graph is a vertex cactus. It is guaranteed that the graph contains no loops or multiple edges. Consider the graph vertices are numbered from 1 to *n*.

Output

Print *k* lines: in the *i*-th line print a single integer — the number of distinct simple ways, starting at *x*_{i} and ending at *y*_{i}, modulo 1000000007 (10^{9} + 7).

Examples

Input

10 11

1 2

2 3

3 4

1 4

3 5

5 6

8 6

8 7

7 6

7 9

9 10

6

1 2

3 5

6 9

9 2

9 3

9 10

Output

2

2

2

4

4

1

Codeforces (c) Copyright 2010-2017 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Mar/26/2017 08:23:42 (c4).

Desktop version, switch to mobile version.
User lists

Name |
---|