#include<cstdio>
#include<stack>
#include<cstring>
using namespace std;
const int M=100010;
int l,l2,type,index,bridge;
struct node{
int d,next;
}edge[4*M],edge2[4*M];
stack<int>s;
int a[M],b[M],dep[M],fat[M],dfn[M],low[M],kind[M],father[M];
void add(int x,int y){
edge[++l].d=y;
edge[l].next=a[x];
a[x]=l;
}
void add2(int x,int y){
edge2[++l2].d=y;
edge2[l2].next=b[x];
b[x]=l2;
}
int find(int x){
if(father[x]==x)return x;
return father[x]=find(father[x]);
}
void tarjan(int x,int p){
int i,y,ok=0;
dfn[x]=low[x]=++index;
s.push(x);
for(i=a[x];i!=-1;i=edge[i].next){
y=edge[i].d;
if(y==p&&ok==0){
ok=1;
continue;
}
if(dfn[y]==0){
tarjan(y,x);
low[x]=min(low[x],low[y]);
if(dfn[x]<low[y])bridge++;
}
else low[x]=min(low[x],low[y]);
}
if(dfn[x]==low[x]){
type++;
while(1){
int y=s.top();
s.pop();
kind[y]=type;
if(x==y)break;
};
}
}
void dfs(int x,int pre){
int i,y;
dep[x]=dep[pre]+1;
for(i=b[x];i!=-1;i=edge2[i].next){
y=edge2[i].d;
if(y!=pre){
fat[y]=x;
dfs(y,x);
}
}
}
void lca(int x,int y){
x=find(x);
y=find(y);
while(x!=y){
if(dep[x]>dep[y]){
bridge--;
father[x]=find(fat[x]);
x=father[x];
}
else if(dep[x]<dep[y]){
bridge--;
father[y]=find(fat[y]);
y=father[y];
}
else{
bridge-=2;
father[x]=find(fat[x]);
father[y]=find(fat[y]);
x=father[x];
y=father[y];
}
}
}
int main(){
int n,m,x,y,i,q,kase=0;
while(scanf("%d%d",&n,&m)&&n&&m){
l=l2=type=index=bridge=0;
memset(a,-1,sizeof(a));
memset(b,-1,sizeof(b));
memset(dfn,0,sizeof(dfn));
memset(dep,0,sizeof(dep));
for(i=1;i<=m;i++){
scanf("%d%d",&x,&y);
add(x,y);
add(y,x);
}
tarjan(1,-1);
for(x=1;x<=n;x++)
for(i=a[x];i!=-1;i=edge[i].next){
y=edge[i].d;
if(kind[x]!=kind[y])
add2(kind[x],kind[y]);
}
dfs(1,0);
for(i=1;i<=type;i++)
father[i]=i;
printf("Case %d:\n",++kase);
scanf("%d",&q);
while(q--){
scanf("%d%d",&x,&y);
lca(kind[x],kind[y]);
printf("%d\n",bridge);
}
}
return 0;
}