// 思路from墨染空大佬,使用oop,lca使用熟悉的bfs
// 割点独立出来
#include<bits/stdc++.h>
using namespace std;
const int N = 20005;
const int M = 200005;
int n, m, Q, num, newId[N];
int c[N], id[M], d[N];
bool vis[N];
vector<int> g[N];
class Tarjan {
public:
int dfn[N], low[N], dfncnt;
vector<int> dcc[N]; int cnt;
bool cut[N];
int s[N], top = 0;
int head[N], bian = 1;
struct edge{
int next, to;
}e[M];
void inline add(int u, int v) {
bian ++;
e[bian].to = v;
e[bian].next = head[u];
head[u] = bian;
}
void init() {
bian = 1;
memset(cut, false, sizeof cut);
memset(head, 0, sizeof head);
memset(dfn, 0, sizeof dfn);
for(int i = 1; i <= cnt; i ++) dcc[i].clear();
dfncnt = cnt = 0;
}
void tarjan(int u, int rt) {
dfn[u] = low[u] = ++ dfncnt;
s[++ top] = u;
if(u == rt && !head[u]) {
dcc[++ cnt].push_back(u);
return;
}
int flag = 0;
for(int i = head[u]; i; i = e[i].next) {
int v = e[i].to;
if(!dfn[v]) {
tarjan(v, rt);
low[u] = min(low[u], low[v]);
if(low[v] >= dfn[u]) {
flag ++;
if(u != rt || flag > 1) cut[u] = true;
int y;
++ cnt;
do {
y = s[top --];
dcc[cnt].push_back(y);
}while(y != v);
dcc[cnt].push_back(u);
}
}
else low[u] = min(low[u], dfn[v]);
}
}
};
Tarjan tar;
class LCA {
// 点从1开始
public:
#define ppp 19
int depth[N], fa[N][ppp];
int bian = 0, head[N];
struct node {
int to;
int next;
}e[M];
void addedge(int u, int v) {
bian ++;
e[bian].to = v;
e[bian].next = head[u];
head[u] = bian;
}
void init() {
bian = 0;
memset(depth, 0x3f, sizeof(depth));
memset(fa, 0, sizeof fa);
memset(head, 0, sizeof head);
}
void bfs(int root) {
depth[0] = 0; depth[root] = 1;
queue<int> q; q.push(root);
if(root > tar.cnt) d[root] ++;
vis[root] = true;
while(!q.empty()) {
int t = q.front(); q.pop();
for(int i = head[t]; i; i = e[i].next) {
int j = e[i].to;
if(depth[j] > depth[t] + 1) {
depth[j] = depth[t] + 1;
q.push(j);
d[j] = d[t];
if(j > tar.cnt) d[j] ++;
vis[j] = true;
fa[j][0] = t;
for(int k = 1; k <= ppp - 1; k ++) {
fa[j][k] = fa[fa[j][k - 1]][k - 1];
}
}
}
}
}
int lca(int a, int b) {
if(depth[a] < depth[b]) swap(a, b);
for(int k = ppp - 1; k >= 0; k --)
if(depth[fa[a][k]] >= depth[b])
a = fa[a][k];
if(a == b) return a;
for(int k = ppp - 1; k >= 0; k --)
if(fa[a][k] != fa[b][k]) {
a = fa[a][k];
b = fa[b][k];
}
return fa[a][0];
}
};
LCA lca;
int main() {
while(scanf("%d%d", &n, &m), n || m) {
lca.init();
for(int i = 1, x, y; i <= m; i ++) {
scanf("%d%d", &x, &y);
tar.add(x, y);
tar.add(y, x);
}
for(int i = 1; i <= n; i ++)
if(!tar.dfn[i]) tar.tarjan(i, i);
num = tar.cnt;
for(int i = 1; i <= n; i ++)
if(tar.cut[i]) newId[i] = ++ num;
for(int i = 1; i <= tar.cnt; i ++) {
for(int j = 0; j < tar.dcc[i].size(); j ++) {
int x = tar.dcc[i][j];
if(tar.cut[x]){
lca.addedge(newId[x], i);
lca.addedge(i, newId[x]);
}
c[x] = i;
}
for (int j = 0; j < tar.dcc[i].size(); j ++) {
int x = tar.dcc[i][j];
for (int k = tar.head[x]; k; k = tar.e[k].next) {
int v = tar.e[k].to;
if(c[v] == i) id[k / 2] = i;
}
}
}
for(int i = 1; i <= num; i ++)
if(!vis[i]) lca.bfs(i);
scanf("%d", &Q);
while(Q --) {
int a, b;
scanf("%d%d", &a, &b);
a = id[a], b = id[b];
int p = lca.lca(a, b);
int tt = d[a] - d[p] + d[b] - d[p];
if(p > tar.cnt) tt ++;
printf("%d\n", tt);
}
memset(newId, 0, sizeof newId);
memset(c, 0, sizeof c);
memset(vis, false, sizeof vis);
memset(id, 0, sizeof id);
lca.init();
tar.init();
}
return 0;
}