import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random #sys.setrecursionlimit(10**9) #n = int(input()) #alist = list(map(int,input().split())) hen = collections.defaultdict(list) #s = input() n,q = map(int,input().split()) ansestor = [[-1 for i in range(n)] for j in range(math.floor(math.log2(n)) + 1)] for i in range(n-1): # alist.append(list(map(int,input().split()))) u,v = map(int,input().split()) u-=1 v-=1 hen[u].append(v) hen[v].append(u) #dp = [[0]*n for i in range(m)] dist = [10**10] * n dist[0] = 0 d = collections.deque() d.append(0) seen = set() seen.add(0) while d: now = d.popleft() for i in hen[now]: if i not in seen: ansestor[0][i] = now d.append(i) dist[i] = dist[now] + 1 seen.add(i) for i in range(math.floor(math.log2(n))): for j in range(n): if ansestor[i][j] == -1: ansestor[i+1][j] = -1 else: ansestor[i+1][j] = ansestor[i][ansestor[i][j]] def ans(u,a): for i in reversed(range(math.floor(math.log2(n)))): if u == -1: break if (a >> i) & 1: u = ansestor[i][u] return u for i in range(q): s,t = map(int,input().split()) s-=1 t-=1 sk = s st = t if dist[s] > dist[t]: s = ans(s,dist[s]-dist[t]) if dist[s] < dist[t]: t = ans(t,-dist[s]+dist[t]) for i in range(math.floor(math.log2(n)),-1,-1): ns = ansestor[i][s] nt = ansestor[i][t] if ns != nt: s = ns t = nt x = ansestor[0][s] if dist[sk] == dist[st]: print(dist[x] + 1) else: z = dist[sk] - dist[x] + dist[st] - dist[x] if z % 2 == 0: print(1) else: print(0)