1 #include <cstdio>
2 #include <iostream>
3 #include <cstring>
4 #include <cmath>
5 using namespace std;
6 const long long mo=1e9+7;
7 struct edge {int to,from;}e[1000010*2];
8 int n,q,head[1000010],cnt;
9 long long sum,f[1000010][20],deep[1000010],ans,k1[1000010],k2[1000010];
10 void insert(int x,int y) {e[++cnt].to=y; e[cnt].from=head[x]; head[x]=cnt;}
11 void dfs(int x,int fa)
12 {
13 f[x][0]=fa;
14 k1[x]=0;
15 for (int i=head[x];i;i=e[i].from)
16 if (e[i].to!=fa)
17 {
18 dfs(e[i].to,x);
19 k1[x]=(k1[x]+k1[e[i].to]+1)%mo;
20 }
21 k1[x]=(k1[x]+1)%mo;
22 }
23 void dfs1(int x,int fa)
24 {
25 long long sum=0;
26 for (int i=head[x];i;i=e[i].from)
27 if (e[i].to!=fa) sum=(sum+k1[e[i].to]+1)%mo;
28 else sum=(sum+k2[x]+1)%mo;
29 for (int i=head[x];i;i=e[i].from)
30 if (e[i].to!=fa)
31 {
32 k2[e[i].to]=((sum-k1[e[i].to])%mo+mo)%mo;
33 dfs1(e[i].to,x);
34 }
35 }
36 void dfs2(int x,int fa)
37 {
38 deep[x]=deep[fa]+1;
39 k1[x]=(k1[x]+k1[fa])%mo,k2[x]=(k2[x]+k2[fa])%mo;
40 for (int i=head[x];i;i=e[i].from)
41 if (e[i].to!=fa)
42 dfs2(e[i].to,x);
43 }
44 int getlca(int u,int w)
45 {
46 if (deep[u]<deep[w]) swap(u,w);
47 int d=deep[u]-deep[w];
48 if (d) for (int i=0;i<=log(n)/log(2)+1&&d;i++,d>>=1) if (d&1) u=f[u][i];
49 if (u==w) return u;
50 for (int i=log(n)/log(2)+1;i>=0;i--)
51 if (f[u][i]!=f[w][i])
52 u=f[u][i],w=f[w][i];
53 return f[u][0];
54 }
55 int main()
56 {
57 freopen("tree.in","r",stdin);
58 freopen("tree.out","w",stdout);
59 scanf("%d%d",&n,&q);
60 for (int i=1;i<=n-1;i++)
61 {
62 int u,v;
63 scanf("%d%d",&u,&v);
64 insert(u,v),insert(v,u);
65 }
66 dfs(1,-1);
67 k1[1]=k2[1]=0;
68 dfs1(1,-1);
69 dfs2(1,-1);
70 for (int i=1;i<=log(n)/log(2)+1;i++)
71 for (int j=1;j<=n;j++)
72 f[j][i]=f[f[j][i-1]][i-1];
73 for (int i=1;i<=q;i++)
74 {
75 int u,v;
76 scanf("%d%d",&u,&v);
77 int lca=getlca(u,v);
78 printf("%lld
",(k1[u]-k1[lca]+k2[v]-k2[lca]+mo)%mo);
79 }
80 return 0;
81 }