You are given a node of the tree with index 1 and with weight 0. Let cnt be the number of nodes in the tree at any instant (initially, cnt is set to 1). Support Q queries of following two types:

  * <image> Add a new node (index cnt + 1) with weight W and add edge between node R and this node. 
  * <image> Output the maximum length of sequence of nodes which 
    1. starts with R. 
    2. Every node in the sequence is an ancestor of its predecessor. 
    3. Sum of weight of nodes in sequence does not exceed X. 
    4. For some nodes i, j that are consecutive in the sequence if i is an ancestor of j then w[i] ≥ w[j] and there should not exist a node k on simple path from i to j such that w[k] ≥ w[j]



The tree is rooted at node 1 at any instant.

Note that the queries are given in a modified way.

Input

First line containing the number of queries Q (1 ≤ Q ≤ 400000).

Let last be the answer for previous query of type 2 (initially last equals 0).

Each of the next Q lines contains a query of following form: 

  * 1 p q (1 ≤ p, q ≤ 1018): This is query of first type where <image> and <image>. It is guaranteed that 1 ≤ R ≤ cnt and 0 ≤ W ≤ 109. 
  * 2 p q (1 ≤ p, q ≤ 1018): This is query of second type where <image> and <image>. It is guaranteed that 1 ≤ R ≤ cnt and 0 ≤ X ≤ 1015. 



<image> denotes bitwise XOR of a and b.

It is guaranteed that at least one query of type 2 exists.

Output

Output the answer to each query of second type in separate line.

Examples

Input

6
1 1 1
2 2 0
2 2 1
1 3 0
2 2 0
2 2 2


Output

0
1
1
2


Input

6
1 1 0
2 2 0
2 0 3
1 0 2
2 1 3
2 1 6


Output

2
2
3
2


Input

7
1 1 2
1 2 3
2 3 3
1 0 0
1 5 1
2 5 0
2 4 0


Output

1
1
2


Input

7
1 1 3
1 2 3
2 3 4
1 2 0
1 5 3
2 5 5
2 7 22


Output

1
2
3

Note

In the first example,

last = 0

- Query 1: 1 1 1, Node 2 with weight 1 is added to node 1.

- Query 2: 2 2 0, No sequence of nodes starting at 2 has weight less than or equal to 0. last = 0

- Query 3: 2 2 1, Answer is 1 as sequence will be {2}. last = 1

- Query 4: 1 2 1, Node 3 with weight 1 is added to node 2. 

- Query 5: 2 3 1, Answer is 1 as sequence will be {3}. Node 2 cannot be added as sum of weights cannot be greater than 1. last = 1

- Query 6: 2 3 3, Answer is 2 as sequence will be {3, 2}. last = 2
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int N = 5e5 + 7;
const int M = 22;
long long w[N], last;
long long sum[N][M];
int nx[N][M], cnt = 1;
void add(int u, int v) {
  if (w[u] <= w[v])
    nx[u][0] = v;
  else {
    for (int i = 20; i >= 0; i--)
      if (nx[v][i] != -1 && w[nx[v][i]] < w[u]) v = nx[v][i];
    nx[u][0] = nx[v][0];
  }
  if (nx[u][0] != -1) sum[u][0] = w[nx[u][0]];
  for (int i = 1; i <= 20; i++) {
    if (nx[u][i - 1] == -1)
      nx[u][i] = -1;
    else {
      nx[u][i] = nx[nx[u][i - 1]][i - 1];
      sum[u][i] = sum[u][i - 1] + sum[nx[u][i - 1]][i - 1];
    }
  }
}
long long cal(int u, long long all) {
  if (w[u] > all) return 0;
  all -= w[u];
  long long ans = 1;
  for (int i = 20; i >= 0; i--) {
    if (u != -1 && all >= sum[u][i]) {
      all -= sum[u][i];
      ans += (1 << i);
      u = nx[u][i];
    }
  }
  return ans;
}
void init() {
  memset(sum, INF, sizeof(sum));
  memset(nx, -1, sizeof(nx));
  w[0] = INF;
}
int main() {
  init();
  int q;
  scanf("%d", &q);
  while (q--) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      long long p, q;
      scanf("%lld", &p);
      scanf("%lld", &q);
      p ^= last;
      q ^= last;
      w[++cnt] = q;
      add(cnt, p);
    } else {
      long long p, q;
      scanf("%lld", &p);
      scanf("%lld", &q);
      p ^= last;
      q ^= last;
      last = cal(p, q);
      printf("%lld\n", last);
    }
  }
  return 0;
}
