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 derrick20
 */
import java.io.*;
import java.util.*;

public class MishaGrishaUnderground {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        int N = sc.nextInt();
        int Q = sc.nextInt();
        parent = new int[17][N];
        adjList = new ArrayList[N];
        Arrays.setAll(adjList, i -> new ArrayList<>());
        for (int i = 1; i <= N - 1; i++) {
            int u = sc.nextInt() - 1;
            parent[0][i] = u;
            adjList[u].add(i);
            adjList[i].add(u);
        }
        parent[0][0] = -1;
        for (int p = 1; p < parent.length; p++) {
            Arrays.fill(parent[p], -1);
            for (int u = 0; u < N; u++) {
                int halfParent = parent[p - 1][u];
                if (halfParent != -1) {
                    parent[p][u] = parent[p - 1][halfParent];
                }
            }
        }

        height = new int[N];
        dfsSetup(0, -1, 0);

        while (Q-->0) {
            int s1 = sc.nextInt() - 1;
            int s2 = sc.nextInt() - 1;
            int f = sc.nextInt() - 1;
            // try using each of them as the destination
            int max = 0;
            for (int i = 0; i < 3; i++) {
                // let c be the destination each time
                int l1 = lca(s1, f);
                int l2 = lca(s2, f);
                int l3 = lca(s1, s2);

                int d = 0;
                if (l1 == l2) {
                    // both below
                    d = dist(s1, f) - dist(s1, l3);
                }
                else if (l1 != f && l2 != f) {
                    // both above
                    d = Math.min(dist(l1, f), dist(l2, f));
                }
                else {
                    // one above, one below
                    d = 0;
                }
//                System.out.println(d + " when " + f + " is the destination");
                // dist + 1 is number of nodes
                max = Math.max(max, d + 1);
                int temp = s1;
                s1 = s2;
                s2 = f;
                f = temp;
            }
            out.println(max);
        }
        out.close();
    }

    static ArrayList<Integer>[] adjList;
    static int[][] parent;
    static int[] height;

    static void dfsSetup(int node, int par, int h) {
        height[node] = h;
        for (int adj : adjList[node]) {
            if (adj != par) {
                dfsSetup(adj, node, h + 1);
            }
        }
    }

    static int dist(int a, int b) {
        int l = lca(a, b);
        int da = height[a] - height[l];
        int db = height[b] - height[l];
        return da + db;
    }

    static int lca(int a, int b) {
        if (height[b] < height[a]) {
            int temp = b;
            b = a;
            a = temp;
        }
        // a is higher up
        for (int p = parent.length - 1; p >= 0; p--) {
            int next = parent[p][b];
            if (next != -1 && height[next] >= height[a]) {
                b = next;
            }
        }
        if (a == b) {
            return a;
        }
        // same height now.
        for (int p = parent.length - 1; p >= 0; p--) {
            int a2 = parent[p][a];
            int b2 = parent[p][b];
            if (a2 != -1 && b2 != -1 && a2 != b2) {
                a = a2;
                b = b2;
            }

        }
        // now, we are as far up as possible while being different
        return parent[0][a];
    }

    static class FastScanner {
        private int BS = 1<<16;
        private char NC = (char)0;
        private byte[] buf = new byte[BS];
        private int bId = 0, size = 0;
        private char c = NC;
        private double cnt = 1;
        private BufferedInputStream in;

        public FastScanner() {
            in = new BufferedInputStream(System.in, BS);
        }

        public FastScanner(String s) {
            try {
                in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
            }
            catch (Exception e) {
                in = new BufferedInputStream(System.in, BS);
            }
        }

        private char getChar(){
            while(bId==size) {
                try {
                    size = in.read(buf);
                }catch(Exception e) {
                    return NC;
                }
                if(size==-1)return NC;
                bId=0;
            }
            return (char)buf[bId++];
        }

        public int nextInt() {
            return (int)nextLong();
        }

        public int[] nextInts(int N) {
            int[] res = new int[N];
            for (int i = 0; i < N; i++) {
                res[i] = (int) nextLong();
            }
            return res;
        }

        public long[] nextLongs(int N) {
            long[] res = new long[N];
            for (int i = 0; i < N; i++) {
                res[i] = nextLong();
            }
            return res;
        }

        public long nextLong() {
            cnt=1;
            boolean neg = false;
            if(c==NC)c=getChar();
            for(;(c<'0' || c>'9'); c = getChar()) {
                if(c=='-')neg=true;
            }
            long res = 0;
            for(; c>='0' && c <='9'; c=getChar()) {
                res = (res<<3)+(res<<1)+c-'0';
                cnt*=10;
            }
            return neg?-res:res;
        }

        public double nextDouble() {
            double cur = nextLong();
            return c!='.' ? cur:cur+nextLong()/cnt;
        }

        public String next() {
            StringBuilder res = new StringBuilder();
            while(c<=32)c=getChar();
            while(c>32) {
                res.append(c);
                c=getChar();
            }
            return res.toString();
        }

        public String nextLine() {
            StringBuilder res = new StringBuilder();
            while(c<=32)c=getChar();
            while(c!='\n') {
                res.append(c);
                c=getChar();
            }
            return res.toString();
        }

        public boolean hasNext() {
            if(c>32)return true;
            while(true) {
                c=getChar();
                if(c==NC)return false;
                else if(c>32)return true;
            }
        }
    }
}