#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair < int , int >;
using i3 = pair < int , ii >;
using li = pair < ll , int >;
using lii = pair < ll , ii >;
using pll = pair < ll , ll >;
using vi = vector < int >;
using vl = vector < ll >;
using vii = vector < ii >;
using vli = vector < li >;
using vpll = vector < pll >;
using vi3 = vector < i3 >;
using vlii = vector < lii >;
const int N = 4e5 + 5 , L = 20;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);
int n , m , q;
vi adj[N] , Tree[N];
int low[N] , dfn[N] , timer = 0;
int dep[N];
int to [N][L];
int sum[N][L];
bool isCutPoint[N];
vii edgesStack;
set < int > belong[N];
int BCC[N];
int bccCount = 0;
set < int > nodes;
int code (int x){ return x + n + 1; }
int decode(int x){ return x - n - 1; }
void processBlock(ii E){
if(edgesStack.empty()) return;
bccCount ++;
while( !edgesStack.empty() ){
ii E2 = edgesStack.back(); edgesStack.pop_back();
int u = E2.first;
int v = E2.second;
belong[u].insert(bccCount);
belong[v].insert(bccCount);
BCC[u] = bccCount;
BCC[v] = bccCount;
if(E2 == E)break;
}
}
void dfs(int u , int p){
dfn[u] = low[u] = ++ timer;
int retchel = 0;
for(int v : adj[u]){
if(!dfn[v]){
edgesStack.push_back({u , v});
retchel ++;
dfs(v , u);
low[u] = min(low[u] , low[v]);
if((p == -1 && retchel > 1) || (p != -1 && dfn[u] <= low[v])){
processBlock({u , v});
isCutPoint[u] = 1;
}
}
else if(v != p){
low[u] = min(low[u] , dfn[v]);
if(dfn[v] < dfn[u]){
edgesStack.push_back({u , v});
}
}
}
}
void buildBCCTree(){
dfs(1 , 0);
processBlock({-1 , -1});
for(int i = 1 ; i <= n ; i ++){
if(isCutPoint[i]){
nodes.insert(i);
for(int compNumber : belong[i]){
int v = code(compNumber);
nodes.insert(v);
Tree[i].push_back(v);
Tree[v].push_back(i);
}
}
}
}
void dfsTree(int u , int p){
to[u][0] = p;
sum[u][0] = (isCutPoint[u]);
dep[u] = 1 + dep[p];
for(int v : Tree[u]){
if(v != p)dfsTree(v , u);
}
}
void traverseForest(){
dfsTree(*(nodes.begin()) , 0);
}
void buildSparseTable(){
for(int j = 1 ; j < L ; j ++){
for(int u : nodes){
to[u][j] = to[ to[u][j-1] ][j-1];
sum[u][j] = sum[u][j-1] + sum[ to[u][j-1] ][j-1];
}
}
}
int getSum(int u , int v){
int ret = 0;
if(u == v) return 0;
if(dep[u] < dep[v]) swap(u , v);
int k = dep[u] - dep[v];
for(int i = 0 ; i < L ; i ++){
if(k & (1 << i)){
ret += sum[u][i];
u = to[u][i];
}
}
if(u == v)return ret + sum[u][0];
for(int i = L-1 ; i >= 0 ; i --){
if(to[u][i] != to[v][i]){
ret += sum[u][i] + sum[v][i];
u = to[u][i];
v = to[v][i];
}
}
return ret + sum[u][0] + sum[v][0] + sum[ to[u][0] ][0];
}
void solve(int testCase){
scanf("%d %d" , &n , &m);
for(int i = 0 ; i < m ; i ++){
int u , v; scanf("%d %d" , &u , &v);
adj[u].push_back(v);
adj[v].push_back(u);
}
buildBCCTree();
traverseForest();
buildSparseTable();
scanf("%d" , &q);
while( q -- ){
int u , v; scanf("%d %d" , &u , &v);
if(!isCutPoint[u])u = code(BCC[u]);
if(!isCutPoint[v])v = code(BCC[v]);
int ans = getSum(u , v) - sum[u][0] - sum[v][0];
printf("%d\n" , max(0 , ans));
}
}
main(){
int t = 1;
// scanf("%d" , &t);
for(int testCase = 1 ; testCase <= t ; testCase ++){
solve(testCase);
}
return 0;
}