#include <bits/stdc++.h>
using namespace std;
//
const int maxn = 1e5 + 5;
const int S = 320;
//
int n, q, a[maxn], p[maxn];
int depth[maxn], cnt[maxn], orz[maxn];
vector<int> adj[maxn];
long long val[maxn][S];
//
void DFS (int u = 1, int d = 0)
{
    depth[u] = d;
    orz[u] = cnt[d]++;
    for (int v : adj[u])
        DFS(v, d + 1);
}
long long query (int x, int y)
{
    if (x == 0 && y == 0)
        return 0;
    if (cnt[depth[x]] < S && val[x][orz[y]] != 0)
        return val[x][orz[y]];
    //
    long long res = query(p[x], p[y]) + 1LL * a[x] * a[y];
    //
    if (cnt[depth[y]] < S)
        val[x][orz[y]] = val[y][orz[x]] = res;
    return res;
}
//
void process (void)
{
    cin >> n >> q;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    for (int i = 2; i <= n; ++i)
        cin >> p[i],
        adj[p[i]].emplace_back(i);

    DFS();

    for (int x, y; q--; cout << '\n')
        cin >> x >> y,
        cout << query(x, y);
}
//
signed main (void)
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    process();
}