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.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 * @author pttrung
 */
public class D_Round_425_Div2 {

    public static long MOD = 1000000007;

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        int n = in.nextInt();
        int q = in.nextInt();
        ArrayList<Integer>[] map = new ArrayList[n];
        HashSet<Integer>[] queries = new HashSet[n];
        HashMap<Integer, Integer>[] re = new HashMap[n];
        int[] u = new int[n];
        for (int i = 0; i < n; i++) {
            re[i] = new HashMap();
            u[i] = i;
            map[i] = new ArrayList();
            queries[i] = new HashSet();
        }
        for (int i = 1; i < n; i++) {
            int v = in.nextInt() - 1;
            map[i].add(v);
            map[v].add(i);
        }
        int[][] data = new int[q][3];

        for (int i = 0; i < q; i++) {
            for (int j = 0; j < 3; j++) {
                data[i][j] = in.nextInt() - 1;
            }
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    if (j != k) {
                        queries[data[i][j]].add(data[i][k]);
                    }
                }
            }
        }
        int[] h = new int[n];
        Arrays.fill(h, -1);
        h[0] = 0;
        LinkedList<Integer> tmp = new LinkedList<>();
        tmp.add(0);
        while (!tmp.isEmpty()) {
            int node = tmp.poll();
            for (int i : map[node]) {
                if (h[i] == -1) {
                    h[i] = 1 + h[node];
                    tmp.add(i);
                }
            }
        }
        update(0, 0, u, new boolean[n], map, queries, re);
        for (int i = 0; i < q; i++) {
            int a = data[i][0];
            int b = data[i][1];
            int c = data[i][2];
            if (h[b] <= h[a] && h[b] <= h[c]) {

                if (h[a] <= h[c]) {
                    a = data[i][1];
                    b = data[i][0];
                } else {
                    a = data[i][1];
                    b = data[i][2];
                    c = data[i][0];
                }
            } else if (h[c] <= h[a] && h[c] <= h[b]) {
                if (h[a] <= h[b]) {
                    a = data[i][2];
                    b = data[i][0];
                    c = data[i][1];
                } else {
                    a = data[i][2];
                    b = data[i][1];
                    c = data[i][0];
                }
            } else if (h[b] > h[c]) {
                b = data[i][2];
                c = data[i][1];
            }

            int v = re[b].get(c);
            int other = re[a].get(b);
            int special = re[a].get(c);
            int result;
            if (q == 1000 && i == 1) {

              //  System.out.println("Test " + a + " " + b + " " + c + " " + h[a] + " " + h[b] + " " + h[c] + " " + v + " " + other + " " + special + " " + h[v] + " " + h[other] + " " + h[special]);
            }
            //System.out.println(a + " " + b + " " + c + " " + queries[a] + " " + queries[b] + " " + queries[c] + " " + re[a] + " " + re[b] + " " + re[c]);
            if (a == b || a == c || b == c) {
                if (a == b) {
                    v = re[b].get(c);
                    result = h[b] - h[v] + h[c] - h[v] + 1;
                } else if (a == c) {
                    v = re[b].get(c);
                    result = h[b] - h[v] + h[c] - h[v] + 1;
                } else {
                    v = re[a].get(c);
                    result = h[a] - h[v] + h[c] - h[v] + 1;
                }
            } else if (other == special) {
                int x = h[a] - h[other] + h[v] - h[other] + 1;
                int y = h[b] - h[v] + 1;
                int z = h[c] - h[v] + 1;
                result = Integer.max(Integer.max(x, y), z);
            } else if (v == special) {
                int x = h[a] - h[other] + 1;
                int y = h[b] - h[other] + 1;
                int z = h[c] - h[special] + h[other] - h[special] + 1;
                result = Integer.max(Integer.max(x, y), z);
            } else {
                int x = h[a] - h[special] + 1;
                int y = h[c] - h[special] + 1;
                int z = h[b] - h[v] + h[special] - h[v] + 1;
                result = Integer.max(Integer.max(x, y), z);
            }
            out.println(result);
        }

        out.close();
    }

    public static void update(int index, int pa, int[] u, boolean[] check, ArrayList<Integer>[] map, HashSet<Integer>[] q, HashMap<Integer, Integer>[] re) {
        for (int i : map[index]) {
            if (i != pa) {
                update(i, index, u, check, map, q, re);
                u[i] = index;
            }
        }
        //System.out.println(map[index] + " " + index);
        //System.out.println("Check " + q[index] + " " + index);
        for (int i : q[index]) {
            if (check[i] || i == index) {
                //System.out.println(i + " " + index);
                int v = find(i, u);
                re[index].put(i, v);
                re[i].put(index, v);
            }
        }
        check[index] = true;
    }

    public static int find(int x, int[] u) {
        if (u[x] == x) {
            return x;
        }
        return u[x] = find(u[x], u);
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, long b, long MOD) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2, MOD);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}
