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.
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.List;

public final class TaskD
{
	public static void main(String[] args)
	{
		new TaskD(System.in, System.out);
	}

	static class Solver
	{
		// BufferedReader in;
		final int INF = (int) 1e9;
		int n, queries, ctr;
		int[] euler, first, depth, tree;
		List<Integer>[] adj;
		InputReader in;
		PrintWriter out;
		
		void solve() throws IOException
		{
			n = in.nextInt();
			queries = in.nextInt();
			adj = new List[n + 1];
			
			for (int i = 0; i <= n; i++)
				adj[i] = new ArrayList<>();
			
			for (int i = 2; i <= n; i++)
			{
				int x = in.nextInt() - 1;
				
				adj[i - 1].add(x);
				adj[x].add(i - 1);
			}
			
//			for (int i = 0; i < n; i++)
//				System.out.println("i : " + i + ", adj[i] : " + adj[i]);
			
			euler = new int[2 * n - 1];
			first = new int[n];
			depth = new int[n];
			tree = new int[n << 4];
			dfs(-1, 0, 1);
			build(1, 0, 2 * n - 2);
			
/*			System.out.println("euler : " + Arrays.toString(euler));
			System.out.println("first : " + Arrays.toString(first));
			System.out.println("depth : " + Arrays.toString(depth));
			System.out.println("tree : " + Arrays.toString(tree));*/
			
			while (queries-- > 0)
			{
				int a, b, c;
				
				a = in.nextInt() - 1;
				b = in.nextInt() - 1;
				c = in.nextInt() - 1;
				out.println(CMath.max(find(a, b, c), find(a, c, b), find(b, c, a)));
			}
		}

		void dfs(int par, int node, int dep)
		{
			euler[ctr] = node;
			first[node] = ctr++;
			depth[node] = dep;

			for (int x : adj[node])
			{
				if (x != par)
				{
					dfs(node, x, dep + 1);
					euler[ctr++] = node;
				}
			}
		}

		void build(int node, int treeStart, int treeEnd)
		{
			if (treeStart == treeEnd)
			{
				tree[node] = treeStart;

				return;
			}

			int mid, left, right;

			mid = treeStart + treeEnd >> 1;
			build(node << 1, treeStart, mid);
			build((node << 1) + 1, mid + 1, treeEnd);
			left = tree[node << 1];
			right = tree[(node << 1) + 1];

			if (depth[euler[left]] < depth[euler[right]])
				tree[node] = left;
			else
				tree[node] = right;
		}

		int query(int node, int treeStart, int treeEnd, int rangeStart, int rangeEnd)
		{
			if (treeStart > rangeEnd || treeEnd < rangeStart)
				return INF;

			if (treeStart >= rangeStart && treeEnd <= rangeEnd)
				return tree[node];

			int mid, left, right;

			mid = treeStart + treeEnd >> 1;
			left = query(node << 1, treeStart, mid, rangeStart, rangeEnd);
			right = query((node << 1) + 1, mid + 1, treeEnd, rangeStart, rangeEnd);
			
			if (left == INF || right == INF)
				return left + right - INF;
			
			if (depth[euler[left]] < depth[euler[right]])
				return left;
			
			return right;
		}
		
		int find(int s, int t, int f)
		{
			if (first[s] > first[t])
			{
				int temp = s;
				
				s = t;
				t = temp;
			}
			
			return (dist(s, f) + dist(f, t) - dist(s, t) + 1) / 2;
			
/*			int sT = euler[query(1, 0, 2 * n - 2, first[s], first[t])];
			
			int dist = dist(sT, f) ;
			System.out.println("s : " + s + ", t : " + t + ", f : " + f + ", sT : " + sT + ", dist : " + dist);
			
			int x = euler[query(1, 0, 2 * n - 2, Math.min(first[sT], first[f]), Math.max(first[sT], first[f]))];
			
			if (depth[sT] < depth[f] && x != sT)
				return dist;
			
			if (sT == f)
				return dist;
			
			return dist + 1;*/
		}
		
		int dist(int a, int b)
		{
//			System.out.println("a : " + a + ", b : " + b);
			
			if (first[a] > first[b])
			{
				int temp = a;
				
				a = b;
				b = temp;
			}
			
//			int lca = query(1, 0, 2 * n - 2, first[a], first[b]);
			
			int lca = euler[query(1, 0, 2 * n - 2, first[a], first[b])];
//			System.out.println("in dist, a : " + a + ", b : " + b + ", lca : " + lca);
//			System.out.println("\tdepth[a] : " + depth[a] + ", depth[b] : " + depth[b] + ", depth[lca] : " + depth[lca]);
			
			return depth[a] - depth[lca] + depth[b] - depth[lca] + 1;
		}

		// uncomment below line to change to BufferedReader
		// public Solver(BufferedReader in, PrintWriter out)
		public Solver(InputReader in, PrintWriter out)
		{
			this.in = in;
			this.out = out;
		}

	}

	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public int read()
		{
			if (numChars == -1)
				throw new InputMismatchException();

			if (curChar >= numChars)
			{
				curChar = 0;
				try
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}

			return buf[curChar++];
		}

		public int nextInt()
		{
			int c = read();

			while (isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-')
			{
				sgn = -1;
				c = read();
			}

			int res = 0;

			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();

				res *= 10;
				res += c & 15;

				c = read();
			} while (!isSpaceChar(c));

			return res * sgn;
		}

		public int[] nextIntArray(int arraySize)
		{
			int array[] = new int[arraySize];

			for (int i = 0; i < arraySize; i++)
				array[i] = nextInt();

			return array;
		}

		public long nextLong()
		{
			int c = read();

			while (isSpaceChar(c))
				c = read();

			int sign = 1;

			if (c == '-')
			{
				sign = -1;

				c = read();
			}

			long result = 0;

			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();

				result *= 10;
				result += c & 15;

				c = read();
			} while (!isSpaceChar(c));

			return result * sign;
		}

		public long[] nextLongArray(int arraySize)
		{
			long array[] = new long[arraySize];

			for (int i = 0; i < arraySize; i++)
				array[i] = nextLong();

			return array;
		}

		public float nextFloat()
		{
			float result, div;
			byte c;

			result = 0;
			div = 1;
			c = (byte) read();

			while (c <= ' ')
				c = (byte) read();

			boolean isNegative = (c == '-');

			if (isNegative)
				c = (byte) read();

			do
			{
				result = result * 10 + c - '0';
			} while ((c = (byte) read()) >= '0' && c <= '9');

			if (c == '.')
				while ((c = (byte) read()) >= '0' && c <= '9')
					result += (c - '0') / (div *= 10);

			if (isNegative)
				return -result;

			return result;
		}

		public double nextDouble()
		{
			double ret = 0, div = 1;
			byte c = (byte) read();

			while (c <= ' ')
				c = (byte) read();

			boolean neg = (c == '-');

			if (neg)
				c = (byte) read();

			do
			{
				ret = ret * 10 + c - '0';
			} while ((c = (byte) read()) >= '0' && c <= '9');

			if (c == '.')
				while ((c = (byte) read()) >= '0' && c <= '9')
					ret += (c - '0') / (div *= 10);

			if (neg)
				return -ret;

			return ret;
		}

		public String next()
		{
			int c = read();

			while (isSpaceChar(c))
				c = read();

			StringBuilder res = new StringBuilder();

			do
			{
				res.appendCodePoint(c);

				c = read();
			} while (!isSpaceChar(c));

			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String nextLine()
		{
			int c = read();

			StringBuilder result = new StringBuilder();

			do
			{
				result.appendCodePoint(c);

				c = read();
			} while (!isNewLine(c));

			return result.toString();
		}

		public boolean isNewLine(int c)
		{
			return c == '\n';
		}

		public void close()
		{
			try
			{
				stream.close();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
		}

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

	}

	static class CMath
	{
		static long power(long number, long power)
		{
			if (number == 1 || number == 0 || power == 0)
				return 1;

			if (power == 1)
				return number;

			if (power % 2 == 0)
				return power(number * number, power / 2);
			else
				return power(number * number, power / 2) * number;
		}

		static long modPower(long number, long power, long mod)
		{
			if (number == 1 || number == 0 || power == 0)
				return 1;

			number = mod(number, mod);

			if (power == 1)
				return number;

			long square = mod(number * number, mod);

			if (power % 2 == 0)
				return modPower(square, power / 2, mod);
			else
				return mod(modPower(square, power / 2, mod) * number, mod);
		}

		static long moduloInverse(long number, long mod)
		{
			return modPower(number, mod - 2, mod);
		}

		static long mod(long number, long mod)
		{
			return number - (number / mod) * mod;
		}

		static int gcd(int a, int b)
		{
			if (b == 0)
				return a;
			else
				return gcd(b, a % b);
		}

		static long min(long... arr)
		{
			long min = arr[0];

			for (int i = 1; i < arr.length; i++)
				min = Math.min(min, arr[i]);

			return min;
		}

		static long max(long... arr)
		{
			long max = arr[0];

			for (int i = 1; i < arr.length; i++)
				max = Math.max(max, arr[i]);

			return max;
		}

		static int min(int... arr)
		{
			int min = arr[0];

			for (int i = 1; i < arr.length; i++)
				min = Math.min(min, arr[i]);

			return min;
		}

		static int max(int... arr)
		{
			int max = arr[0];

			for (int i = 1; i < arr.length; i++)
				max = Math.max(max, arr[i]);

			return max;
		}

	}
	
	public TaskD(InputStream inputStream, OutputStream outputStream)
	{
		// uncomment below line to change to BufferedReader
		// BufferedReader in = new BufferedReader(new
		// InputStreamReader(inputStream));
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Solver solver = new Solver(in, out);

		try
		{
			solver.solve();
			in.close();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}

		out.flush();
		out.close();
	}

}

/*

3 2
1 1
1 2 3
2 3 3
: 2, 3

3 1
1 1
1 2 3

4 1
1 2 3
1 2 3
: 2

6 4
1 2 2 1 2
1 3 4
2 3 4
3 4 5
2 3 5

6 1
1 2 2 1 2
1 3 4

*/
