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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.File;
import java.util.ArrayList;
import java.io.FilterInputStream;
import java.util.ArrayDeque;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Atharva Nagarkar
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        JoltyScanner in = new JoltyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemDMishaGrishaAndUnderground solver = new ProblemDMishaGrishaAndUnderground();
        solver.solve(1, in, out);
        out.close();
    }

    static class ProblemDMishaGrishaAndUnderground {
        int n;
        int q;

        public void solve(int testNumber, JoltyScanner in, PrintWriter out) {
            n = in.nextInt();
            q = in.nextInt();
            HLD tree = new HLD(n);
            for (int i = 1; i < n; ++i) {
                int u = in.nextInt() - 1;
                tree.add(u, i);
            }
            tree.go(0);
            while (q-- > 0) {
                int a = in.nextInt() - 1;
                int b = in.nextInt() - 1;
                int c = in.nextInt() - 1;
                int[] perm = {a, b, c};
                int ans = 0;
                for (int i = 0; i < 3; ++i) {
                    for (int j = 0; j < 3; ++j)
                        if (i != j) {
                            for (int k = 0; k < 3; ++k)
                                if (k != i && k != j) {
                                    int s = perm[i], t = perm[j], f = perm[k];
                                    tree.update(s, f, 1);
                                    int cur = tree.count(t, f);
                                    tree.update(s, f, -1);
                                    ans = Math.max(ans, cur);
                                }
                        }
                }
                out.println(ans);
            }
        }

    }

    static class SuperBIT_INT {
        int[] dataMul;
        int[] dataAdd;

        public SuperBIT_INT(int n) {
            dataMul = new int[n];
            dataAdd = new int[n];
        }

        public void update(int left, int right, int val) {
            internalUpdate(left, val, -val * (left - 1));
            internalUpdate(right, -val, val * right);
        }

        public void internalUpdate(int at, int mul, int add) {
            while (at < dataMul.length) {
                dataMul[at] += mul;
                dataAdd[at] += add;
                at |= (at + 1);
            }
        }

        public int query(int at) {
            int mul = 0;
            int add = 0;
            int start = at;
            while (at >= 0) {
                mul += dataMul[at];
                add += dataAdd[at];
                at = (at & (at + 1)) - 1;
            }
            return mul * start + add;
        }

        public int query(int left, int right) {
            if (left > right) {
                int temp = left;
                left = right;
                right = temp;
            }
            return query(right) - (left > 0 ? query(left - 1) : 0);
        }

    }

    static class HLD {
        public int[] h2v;
        public int[] v2h;
        public int[] hp;
        public int[] lp;
        public int[] size;
        public int[] par;
        public SuperBIT_INT bit;
        public ArrayList<Integer>[] adj;
        public int n;

        public HLD(int N) {
            adj = new ArrayList[n = N];
            bit = new SuperBIT_INT(n);
            for (int i = 0; i < n; ++i)
                adj[i] = new ArrayList<>();
            h2v = new int[n];
            v2h = new int[n];
            hp = new int[n];
            lp = new int[n];
            size = new int[n];
            par = new int[n];
            Arrays.fill(size, 1);
            Arrays.fill(par, -1);
        }

        public void add(int v1, int v2) {
            adj[v1].add(v2);
            adj[v2].add(v1);
        }

        public void go(int s) {
            dfs(s);
            ArrayDeque<Integer> q = new ArrayDeque<>();
            q.add(s);
            int ind = lp[s] = hp[s] = 0;
            while (!q.isEmpty()) {
                int at = q.poll(), h = ind;
                if (at != s) lp[at] = v2h[par[at]];
                int l = lp[at];
                while (true) {
                    for (int c = 1; c < adj[at].size(); ++c) {
                        int u = adj[at].get(c);
                        if (u == par[at]) continue;
                        q.push(u);
                    }
                    lp[at] = l;
                    hp[at] = h;
                    h2v[ind] = at;
                    v2h[at] = ind++;
                    if (adj[at].size() <= 1 && at != s) break;
                    at = adj[at].get(0);
                }
            }
        }

        public void dfs(int v) {
            int max = 0, m = 0;
            for (int c = 0; c < adj[v].size(); ++c) {
                int u = adj[v].get(c);
                if (u == par[v]) continue;
                par[u] = v;
                dfs(u);
                int s = size[u];
                size[v] += s;
                if (m < s) {
                    max = c;
                    m = s;
                }
            }
            if (max > 0)
                Collections.swap(adj[v], 0, max);
        }

        public int count(int v1, int v2) {
            int n1 = v2h[v1], n2 = v2h[v2];
            int ans = 0;
            while (true) {
                if (hp[h2v[n1]] == hp[h2v[n2]]) {
                    ans += bit.query(n1, n2);
                    break;
                } else if (n1 > n2) {
                    ans += bit.query(hp[h2v[n1]], n1);
                    n1 = lp[h2v[n1]];
                } else {
                    ans += bit.query(hp[h2v[n2]], n2);
                    n2 = lp[h2v[n2]];
                }
            }
            return ans;
        }

        public void update(int v1, int v2, int delta) {
            int n1 = v2h[v1], n2 = v2h[v2];
            while (true) {
                if (hp[h2v[n1]] == hp[h2v[n2]]) {
                    int min = n1 < n2 ? n1 : n2;
                    int max = n2 < n1 ? n1 : n2;
                    bit.update(min, max, delta);
                    break;
                } else if (n1 > n2) {
                    bit.update(hp[h2v[n1]], n1, delta);
                    n1 = lp[h2v[n1]];
                } else {
                    bit.update(hp[h2v[n2]], n2, delta);
                    n2 = lp[h2v[n2]];
                }
            }
        }

    }

    static class JoltyScanner {
        public int BS = 1 << 16;
        public char NC = (char) 0;
        public byte[] buf = new byte[BS];
        public int bId = 0;
        public int size = 0;
        public char c = NC;
        public double num = 1;
        public BufferedInputStream in;

        public JoltyScanner(InputStream is) {
            in = new BufferedInputStream(is, BS);
        }

        public JoltyScanner(String s) throws FileNotFoundException {
            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
        }

        public char nextChar() {
            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 long nextLong() {
            num = 1;
            boolean neg = false;
            if (c == NC) c = nextChar();
            for (; (c < '0' || c > '9'); c = nextChar()) {
                if (c == '-') neg = true;
            }
            long res = 0;
            for (; c >= '0' && c <= '9'; c = nextChar()) {
                res = (res << 3) + (res << 1) + c - '0';
                num *= 10;
            }
            return neg ? -res : res;
        }

    }
}

