In Berland each feudal owns exactly one castle and each castle belongs to exactly one feudal.

Each feudal, except one (the King) is subordinate to another feudal. A feudal can have any number of vassals (subordinates).

Some castles are connected by roads, it is allowed to move along the roads in both ways. Two castles have a road between them if and only if the owner of one of these castles is a direct subordinate to the other owner.

Each year exactly one of these two events may happen in Berland.

  1. The barbarians attacked castle c. The interesting fact is, the barbarians never attacked the same castle twice throughout the whole Berlandian history. 
  2. A noble knight sets off on a journey from castle a to castle b (provided that on his path he encounters each castle not more than once). 



Let's consider the second event in detail. As the journey from a to b is not short, then the knight might want to stop at a castle he encounters on his way to have some rest. However, he can't stop at just any castle: his nobility doesn't let him stay in the castle that has been desecrated by the enemy's stench. A castle is desecrated if and only if it has been attacked after the year of y. So, the knight chooses the k-th castle he encounters, starting from a (castles a and b aren't taken into consideration), that hasn't been attacked in years from y + 1 till current year.

The knights don't remember which castles were attacked on what years, so he asked the court scholar, aka you to help them. You've got a sequence of events in the Berland history. Tell each knight, in what city he should stop or else deliver the sad news — that the path from city a to city b has less than k cities that meet his requirements, so the knight won't be able to rest.

Input

The first input line contains integer n (2 ≤ n ≤ 105) — the number of feudals. 

The next line contains n space-separated integers: the i-th integer shows either the number of the i-th feudal's master, or a 0, if the i-th feudal is the King. 

The third line contains integer m (1 ≤ m ≤ 105) — the number of queries.

Then follow m lines that describe the events. The i-th line (the lines are indexed starting from 1) contains the description of the event that occurred in year i. Each event is characterised by type ti (1 ≤ ti ≤ 2). The description of the first type event looks as two space-separated integers ti ci (ti = 1; 1 ≤ ci ≤ n), where ci is the number of the castle that was attacked by the barbarians in the i-th year. The description of the second type contains five space-separated integers: ti ai bi ki yi (ti = 2; 1 ≤ ai, bi, ki ≤ n; ai ≠ bi; 0 ≤ yi < i), where ai is the number of the castle from which the knight is setting off, bi is the number of the castle to which the knight is going, ki and yi are the k and y from the second event's description.

You can consider the feudals indexed from 1 to n. It is guaranteed that there is only one king among the feudals. It is guaranteed that for the first type events all values ci are different.

Output

For each second type event print an integer — the number of the castle where the knight must stay to rest, or -1, if he will have to cover the distance from ai to bi without a rest. Separate the answers by whitespaces.

Print the answers in the order, in which the second type events are given in the input.

Examples

Input

3
0 1 2
5
2 1 3 1 0
1 2
2 1 3 1 0
2 1 3 1 1
2 1 3 1 2


Output

2
-1
-1
2


Input

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


Output

5
-1

Note

In the first sample there is only castle 2 on the knight's way from castle 1 to castle 3. When the knight covers the path 1 - 3 for the first time, castle 2 won't be desecrated by an enemy and the knight will stay there. In the second year the castle 2 will become desecrated, so the knight won't have anywhere to stay for the next two years (as finding a castle that hasn't been desecrated from years 1 and 2, correspondingly, is important for him). In the fifth year the knight won't consider the castle 2 desecrated, so he will stay there again.
#include <bits/stdc++.h>
using namespace std;
struct apple {
  int v, nxt;
} edge[100011 * 4];
struct node {
  int l, r, lson, rson, sum, len;
} tree[100011 * 30];
int indexx[100011], tt[100011], root[100011], f[100011], max_son[100011],
    wgt[100011], fa[100011], top[100011], tot, siz, Root, deep[100011];
int sumx, ti, sum, ans, n, m;
void addedge(int x, int y) {
  edge[++tot].v = y;
  edge[tot].nxt = indexx[x];
  indexx[x] = tot;
}
void push_up(int now) {
  int l = tree[now].lson, r = tree[now].rson;
  tree[now].sum = tree[l].sum + tree[r].sum;
}
void build(int l, int r, int &now) {
  now = ++siz;
  tree[now].l = l;
  tree[now].r = r;
  tree[now].len = (r - l + 1);
  if (l == r) {
    tree[now].sum = 0;
    return;
  }
  int mid = (l + r) / 2;
  build(l, mid, tree[now].lson);
  build(mid + 1, r, tree[now].rson);
  push_up(now);
}
void add(int &now, int k, int p, int x) {
  now = ++siz;
  tree[now] = tree[k];
  if (tree[now].l == tree[now].r) {
    tree[now].sum++;
    return;
  }
  int mid = (tree[now].l + tree[now].r) / 2;
  if (p <= mid)
    add(tree[now].lson, tree[k].lson, p, x);
  else
    add(tree[now].rson, tree[k].rson, p, x);
  push_up(now);
}
int query(int now, int k, int l, int r) {
  if (l <= tree[now].l && tree[now].r <= r) {
    return tree[now].len - (tree[now].sum - tree[k].sum);
  }
  int mid = (tree[now].l + tree[now].r) / 2, ret = 0;
  if (l <= mid) ret += query(tree[now].lson, tree[k].lson, l, r);
  if (r > mid) ret += query(tree[now].rson, tree[k].rson, l, r);
  return ret;
}
void basic_dfs(int u, int dep) {
  deep[u] = dep;
  wgt[u] = 1;
  int t = indexx[u], vv, maxx = 0;
  while (t) {
    vv = edge[t].v;
    if (vv != fa[u]) {
      basic_dfs(vv, dep + 1);
      wgt[u] += wgt[vv];
      if (wgt[vv] > maxx) {
        max_son[u] = vv;
        maxx = wgt[vv];
      }
    }
    t = edge[t].nxt;
  }
}
void build_dfs(int u, int anc) {
  top[u] = anc;
  tt[u] = ++ti;
  f[ti] = u;
  if (max_son[u]) {
    build_dfs(max_son[u], anc);
  }
  int t = indexx[u], vv;
  while (t) {
    vv = edge[t].v;
    if (vv != max_son[u]) build_dfs(vv, vv);
    t = edge[t].nxt;
  }
}
int bin(int head, int tail, int i, int k, int num) {
  int s = tail, mid, ret;
  while (head <= tail) {
    mid = (head + tail) / 2;
    if (query(root[i], root[k], mid, s) >= num) {
      ret = mid;
      head = mid + 1;
    } else
      tail = mid - 1;
  }
  return ret;
}
int solve1(int x, int y, int i, int k) {
  int ret = 0, t;
  t = query(root[i], root[k], tt[x], tt[x]);
  sumx -= t;
  ret -= t;
  ret -= query(root[i], root[k], tt[y], tt[y]);
  while (top[x] != top[y]) {
    if (deep[top[x]] > deep[top[y]]) {
      t = query(root[i], root[k], tt[top[x]], tt[x]);
      ret += t;
      sumx += t;
      x = fa[top[x]];
    } else {
      ret += query(root[i], root[k], tt[top[y]], tt[y]);
      y = fa[top[y]];
    }
  }
  if (deep[x] >= deep[y]) {
    t = query(root[i], root[k], tt[y], tt[x]);
    ret += t;
    sumx += t;
  } else {
    ret += query(root[i], root[k], tt[x], tt[y]);
  }
  return ret;
}
int solve2(int x, int num, int i, int k) {
  int temp, ret;
  num += query(root[i], root[k], tt[x], tt[x]);
  while (x) {
    temp = query(root[i], root[k], tt[top[x]], tt[x]);
    if (num > temp) {
      num -= temp;
      x = fa[top[x]];
    } else {
      ret = bin(tt[top[x]], tt[x], i, k, num);
      return f[ret];
    }
  }
  return 0;
}
void Attack(int i) {
  int x;
  scanf("%d", &x);
  add(root[i], root[i - 1], tt[x], 1);
}
void Travel(int i) {
  int x, y, k, pre;
  root[i] = root[i - 1];
  scanf("%d%d%d%d", &x, &y, &k, &pre);
  sumx = 0;
  sum = solve1(x, y, i, pre);
  if (sum < k) {
    printf("-1\n");
    return;
  }
  if (sumx >= k) {
    ans = solve2(x, k, i, pre);
  } else {
    ans = solve2(y, sum - k + 1, i, pre);
  }
  printf("%d\n", ans);
}
int main() {
  int op;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &fa[i]);
    if (fa[i])
      addedge(fa[i], i);
    else
      Root = i;
  }
  basic_dfs(Root, 1);
  build_dfs(Root, Root);
  build(1, n, root[0]);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &op);
    if (op == 1) {
      Attack(i);
    } else {
      Travel(i);
    }
  }
  return 0;
}
