#include <bits/stdc++.h>
const int N = 2e5 + 5;
int n, q, tot = 1, d1[N], d2[N], rev[N];
std::vector<int> t[N];
int rt, fa[N], ch[N][2], val[N], mn[N], mx[N], lz[N];
inline void pushup(int x) {
  int l = ch[x][0], r = ch[x][1];
  mn[x] = std::min(val[x], std::min(mn[l], mn[r]));
  mx[x] = std::max(val[x], std::max(mx[l], mx[r]));
}
inline void tg(int x, int v) {
  if (x) val[x] += v, mn[x] += v, mx[x] += v, lz[x] += v;
}
inline void pushdown(int x) {
  if (lz[x]) tg(ch[x][0], lz[x]), tg(ch[x][1], lz[x]), lz[x] = 0;
}
inline void rot(int x) {
  int y = fa[x], z = fa[y], k = ch[y][1] == x;
  ch[z][ch[z][1] == y] = x, fa[x] = z, ch[y][k] = ch[x][!k], fa[ch[x][!k]] = y,
                    ch[x][!k] = y, fa[y] = x, pushup(y), pushup(x);
}
inline void splay(int x, int g) {
  int y, z;
  for (pushdown(x); fa[x] != g; rot(x)) {
    y = fa[x], z = fa[y], pushdown(z), pushdown(y), pushdown(x);
    if (z != g) (ch[z][0] == y) ^ (ch[y][0] == x) ? rot(x) : rot(y);
  }
  if (!g) rt = x;
}
inline void split(int x, int y) { splay(x, 0), splay(y, x); }
inline int find(int x, int v) {
  int l = ch[x][0], r = ch[x][1];
  pushdown(x);
  if (mn[r] <= v && v <= mx[r]) return find(r, v);
  return val[x] == v ? x : find(l, v);
}
inline int nx(int x, int o) {
  for (splay(x, 0), x = ch[x][o]; ch[x][!o]; x = ch[x][!o])
    ;
  return pushdown(x), x;
}
inline void build(int &p, int l, int r, int f) {
  if (l > r) return;
  fa[p = l + r >> 1] = f;
  build(ch[p][0], l, p - 1, p), build(ch[p][1], p + 1, r, p), pushup(p);
}
inline void dfs(int u, int d) {
  d1[u] = ++tot, rev[tot] = u, val[tot] = d;
  for (int v : t[u]) dfs(v, d + 1);
  d2[u] = ++tot, rev[tot] = u, val[tot] = d;
}
inline int ask(int x, int y) {
  if (x == y) return 0;
  x = d1[x], y = d1[y], split(x, y);
  int z = mn[ch[y][ch[x][0] == y]];
  return val[x] + val[y] - 2 * std::min(z - 1, std::min(val[x], val[y]));
}
inline void upt(int x, int h) {
  int u = d1[x], l, r, z, w;
  split(1, u), z = rev[find(ch[u][0], val[u] - h)];
  l = nx(u, 0), r = nx(d2[x], 1), split(l, r), w = ch[r][0], ch[r][0] = 0,
  pushup(l), pushup(r);
  r = d2[z], l = nx(r, 0), split(l, r), ch[r][0] = w, fa[w] = r, tg(w, 1 - h),
  splay(w, 0);
}
int main() {
  scanf("%d%d", &n, &q), memset(mn, 63, sizeof mn), memset(mx, -63, sizeof mx);
  int i, x, y;
  for (i = 1; i <= n; i++)
    for (scanf("%d", &x); x; x--) scanf("%d", &y), t[i].push_back(y);
  dfs(1, 1), build(rt, 1, ++tot, 0);
  while (q--) {
    scanf("%d%d", &i, &x);
    if (i < 3) scanf("%d", &y);
    if (i == 1) printf("%d\n", ask(x, y));
    if (i == 2) upt(x, y);
    if (i == 3) printf("%d\n", rev[find(rt, x + 1)]);
  }
  return 0;
}
