Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected with n - 1 routes so that each route connects two stations, and it is possible to reach every station from any other.

The boys decided to have fun and came up with a plan. Namely, in some day in the morning Misha will ride the underground from station s to station f by the shortest path, and will draw with aerosol an ugly text "Misha was here" on every station he will pass through (including s and f). After that on the same day at evening Grisha will ride from station t to station f by the shortest path and will count stations with Misha's text. After that at night the underground workers will wash the texts out, because the underground should be clean. 

The boys have already chosen three stations a, b and c for each of several following days, one of them should be station s on that day, another should be station f, and the remaining should be station t. They became interested how they should choose these stations s, f, t so that the number Grisha will count is as large as possible. They asked you for help.

Input

The first line contains two integers n and q (2 ≤ n ≤ 105, 1 ≤ q ≤ 105) — the number of stations and the number of days.

The second line contains n - 1 integers p2, p3, ..., pn (1 ≤ pi ≤ n). The integer pi means that there is a route between stations pi and i. It is guaranteed that it's possible to reach every station from any other.

The next q lines contains three integers a, b and c each (1 ≤ a, b, c ≤ n) — the ids of stations chosen by boys for some day. Note that some of these ids could be same.

Output

Print q lines. In the i-th of these lines print the maximum possible number Grisha can get counting when the stations s, t and f are chosen optimally from the three stations on the i-th day.

Examples

Input

3 2
1 1
1 2 3
2 3 3


Output

2
3


Input

4 1
1 2 3
1 2 3


Output

2

Note

In the first example on the first day if s = 1, f = 2, t = 3, Misha would go on the route 1 <image> 2, and Grisha would go on the route 3 <image> 1 <image> 2. He would see the text at the stations 1 and 2. On the second day, if s = 3, f = 2, t = 3, both boys would go on the route 3 <image> 1 <image> 2. Grisha would see the text at 3 stations.

In the second examle if s = 1, f = 3, t = 2, Misha would go on the route 1 <image> 2 <image> 3, and Grisha would go on the route 2 <image> 3 and would see the text at both stations.
/*
 * Author Ayub Subhaniya
 * Institute DA-IICT
 */

import java.io.*;
import java.math.*;
import java.util.*;

public class Codeforces461{
	
	InputStream in;
	PrintWriter out;
	
	ArrayList<Integer> g[];
	void solve() throws IOException {
		int n=ni();
		int q=ni();
		g=new ArrayList[n+1];
		for (int i=0;i<=n;i++)
			g[i]=new ArrayList<Integer>();
		for (int i=2;i<=n;i++)
		{
			int a=ni();
			g[a].add(i);
			g[i].add(a);
		}
		preprocess(n+1, 1);
		int a,b,c;
		while (q-->0)
		{
			a=ni();b=ni();c=ni();
			//tr(a+" "+b+" "+c);
			if (ismiddle(b, c, a))
			{
				//tr("m->"+a+" "+eval(b,a,c));
				out.println(eval(b, a, c));
			}
			else if (ismiddle(a, c, b))
			{
				//tr("m->"+b+" "+eval(a, b, c));
				out.println(eval(a, b, c));
			}
			else if (ismiddle(b, a, c))
			{
				//tr("m->"+c+" "+eval(b, c, a));
				out.println(eval(b, c, a));
			}
		}
	}
	
	int len;
	int[][] up;
	int[] tin;
	int[] tout;
	int time;
	int[] depth;

	void dfs(int u, int p, int level) {
		depth[u] = level;
		tin[u] = time++;
		up[0][u] = p;
		for (int i = 1; i < len; i++)
			up[i][u] = up[i - 1][up[i - 1][u]];
		for (int v : g[u])
			if (v != p)
				dfs(v, u, level + 1);
		tout[u] = time++;
	}
	
	boolean ismiddle(int f,int t,int s)
	{
		int lca=lca(f,t);
		return (isParent(lca, s) && (isParent(s, f)||isParent(s, t)||(!isLeft(f, t, s)&&!isRight(f, t, s))));
	}
	
	boolean isLeft(int f,int t,int s)
	{
		return tout[s]<=tin[f]&&tout[s]<=tin[t];
	}
	
	boolean isRight(int f,int t,int s)
	{
		return tin[s]>=tout[f]&&tin[s]>=tout[t];
	}
	
	int eval(int a,int b,int c)
	{
		int l1=lca(a,b);
		int l2=lca(b,c);
		
		if (isParent(l1, l2))
		{
			return Math.max(distance(l2, a), Math.max(distance(l2, b), distance(l2, c)));
		}
		else
		{
			return Math.max(distance(l1, a), Math.max(distance(l1, b), distance(l1, c)));
		}
	}

	boolean isParent(int parent, int child) {
		return tin[parent] <= tin[child] && tout[child] <= tout[parent];
	}
	
	int lca(int a, int b) {
		if (isParent(a, b))
			return a;
		if (isParent(b, a))
			return b;
		for (int i = len - 1; i >= 0; i--)
			if (!isParent(up[i][a], b))
				a = up[i][a];
		return up[0][a];
	}

	void preprocess(int n, int root) {

		len = 1;
		while ((1 << len) <= n)
			++len;
		up = new int[len][n];
		tin = new int[n];
		tout = new int[n];
		depth = new int[n];
		dfs(root, root, 0);
	}

	int distance(int a, int b) {
		return depth[a] + depth[b] - 2 * depth[lca(a, b)]+1;
	}
	
	
	
	void run() throws Exception {
		String INPUT = "C:/Users/ayubs/Desktop/input.txt";
		in = oj ? System.in : new FileInputStream(INPUT);
		out = new PrintWriter(System.out);
		
			long s = System.currentTimeMillis();
			solve();
			out.flush();
			tr(System.currentTimeMillis() - s + "ms");
	}
	public static void main(String[] args) throws Exception {
		new Codeforces461().run();
	}
	
	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;
	
	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = in.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private boolean inSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}
	
	private int skip() {
		int b;
		while ((b = readByte()) != -1 && inSpaceChar(b))
			;
		return b;
	}
	
	private double nd() {
		return Double.parseDouble(ns());
	}
	
	private char nc() {
		return (char) skip();
	}
	
	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(inSpaceChar(b))) { // when nextLine, (inSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(inSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}
	
	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	
	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		
		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		
		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	
	private void tr(Object... o) {
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}
	
}
