Problem: It is the year 2969. 1000 years have passed from the moon landing. Meanwhile, the humanity colonized the Hyperspace™ and lived in harmony.

Until we realized that we were not alone.

Not too far away from the Earth, the massive fleet of aliens' spaceships is preparing to attack the Earth. For the first time in a while, the humanity is in real danger. Crisis and panic are everywhere. The scientists from all around the solar system have met and discussed the possible solutions. However, no progress has been made.

The Earth's last hope is YOU!

Fortunately, the Earth is equipped with very powerful defense systems made by MDCS. There are N aliens' spaceships which form the line. The defense system consists of three types of weapons: 

  * SQL rockets – every SQL rocket can destroy at most one spaceship in the given set.
  * Cognition beams – every Cognition beam has an interval [l,r] and can destroy at most one spaceship in that interval.
  * OMG bazooka – every OMG bazooka has three possible targets, however, each bazooka can destroy either zero or exactly two spaceships. In addition, due to the smart targeting system, the sets of the three possible targets of any two different OMG bazookas are disjoint (that means that every ship is targeted with at most one OMG bazooka). 



Your task is to make a plan of the attack which will destroy the largest possible number of spaceships. Every destroyed spaceship should be destroyed with exactly one weapon.

Input

The first line contains two integers: the number of your weapons N (1≤ N≤ 5000) and the number of spaceships M (1≤ M≤ 5000).

In the next N lines, each line starts with one integer that represents type (either 0, 1 or 2). If the type is 0, then the weapon is SQL rocket, the rest of the line contains strictly positive number K (∑{K} ≤ 100 000) and array k_i (1≤ k_i≤ M) of K integers. If the type is 1, then the weapon is Cognition beam, the rest of the line contains integers l and r (1≤ l≤ r≤ M). If the type is 2 then the weapon is OMG bazooka, the rest of the line contains distinct numbers a, b and c  (1 ≤ a,b,c ≤ M).

Output

The first line should contain the maximum number of destroyed spaceships — X.

In the next X lines, every line should contain two numbers A and B, where A is an index of the weapon and B is an index of the spaceship which was destroyed by the weapon A.

Example

Input

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


Output

4
2 1
3 2
1 4
2 5

Note

SQL rocket can destroy only 4th spaceship. OMG Bazooka can destroy two of 1st, 4th or 5th spaceship, and Cognition beam can destroy any spaceship from the interval [1,4]. The maximum number of destroyed spaceship is 4, and one possible plan is that SQL rocket should destroy 4th spaceship, OMG bazooka should destroy 1st and 5th spaceship and Cognition beam should destroy 2nd spaceship.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 40010;
const int inf = 1e9 + 10;
class edge {
 public:
  int to, nxt, cap;
} E[2000010];
namespace F {
int m, cnt = 0;
int head[maxn], level[maxn], iter[maxn];
void add_edge(int u, int v, int cap) {
  E[cnt] = (edge){v, head[u], cap};
  head[u] = cnt++;
  E[cnt] = (edge){u, head[v], 0};
  head[v] = cnt++;
}
int Q[maxn];
void bfs(int s) {
  memset(level, -1, sizeof(level));
  int st = 0, ed = 0;
  Q[ed++] = s;
  level[s] = 0;
  while (st < ed) {
    int x = Q[st++];
    for (int i = head[x]; i != -1; i = E[i].nxt) {
      edge &e = E[i];
      if (e.cap > 0 && level[e.to] < 0) {
        level[e.to] = level[x] + 1;
        Q[ed++] = e.to;
      }
    }
  }
}
int dfs(int x, int t, int f) {
  if (x == t) return f;
  for (int &i = iter[x]; i != -1; i = E[i].nxt) {
    edge &e = E[i];
    if (e.cap > 0 && level[x] < level[e.to]) {
      int d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        E[i ^ 1].cap += d;
        return d;
      }
    }
  }
  return 0;
}
int max_flow(int s, int t) {
  int flow = 0;
  while (true) {
    bfs(s);
    if (level[t] < 0) return flow;
    memcpy(iter, head, sizeof(iter));
    while (true) {
      int f = dfs(s, t, inf);
      flow += f;
      if (f <= 0) break;
    }
  }
  return flow;
}
}  // namespace F
int tree[maxn * 3];
void build_tree(int x, int l, int r) {
  if (l == r) {
    tree[x] = l;
    return;
  }
  tree[x] = F::m++;
  int mid = (l + r) >> 1;
  build_tree(x << 1, l, mid);
  build_tree(x << 1 | 1, mid + 1, r);
  F::add_edge(tree[x << 1], tree[x], inf);
  F::add_edge(tree[x << 1 | 1], tree[x], inf);
}
void add_edge(int x, int l, int r, int cl, int cr, int tmp) {
  if (l == cl && r == cr) {
    F::add_edge(tree[x], tmp, 1);
    return;
  }
  int mid = (l + r) >> 1;
  if (cr <= mid) {
    add_edge(x << 1, l, mid, cl, cr, tmp);
  } else if (cl >= mid + 1) {
    add_edge(x << 1 | 1, mid + 1, r, cl, cr, tmp);
  } else {
    add_edge(x << 1, l, mid, cl, mid, tmp);
    add_edge(x << 1 | 1, mid + 1, r, mid + 1, cr, tmp);
  }
}
vector<pair<pair<int, int>, pair<int, int> > > v;
void get_ans(int x, int l, int r, int cl, int cr, int tmp, int id) {
  if (l == cl && r == cr) {
    for (int i = F::head[tmp]; i != -1; i = E[i].nxt) {
      edge &e = E[i];
      if (e.to == tree[x] && e.cap == 1) {
        v.push_back(make_pair(make_pair(r - l + 1, id), make_pair(l, r)));
        return;
      }
    }
    return;
  }
  int mid = (l + r) >> 1;
  if (cr <= mid) {
    get_ans(x << 1, l, mid, cl, cr, tmp, id);
  } else if (cl >= mid + 1) {
    get_ans(x << 1 | 1, mid + 1, r, cl, cr, tmp, id);
  } else {
    get_ans(x << 1, l, mid, cl, mid, tmp, id);
    get_ans(x << 1 | 1, mid + 1, r, mid + 1, cr, tmp, id);
  }
}
int n, q;
int ID[maxn], type[maxn], L[maxn], R[maxn];
bool ok[maxn];
int read() {
  int res = 0;
  char c = getchar();
  while ('0' <= c && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
  }
  return res;
}
int main() {
  memset(F::head, -1, sizeof(F::head));
  q = read();
  n = read();
  int s = n, t = n + 1;
  F::m = t + 1;
  for (int i = 0; i < n; i++) F::add_edge(s, i, 1);
  build_tree(1, 0, n - 1);
  for (int i = 0; i < q; i++) {
    type[i] = read();
    if (type[i] == 0) {
      int k = read();
      int tmp = F::m++;
      ID[i] = tmp;
      while (k--) {
        int x = read();
        x--;
        F::add_edge(x, tmp, 1);
      }
      F::add_edge(tmp, t, 1);
    } else if (type[i] == 2) {
      int a = read(), b = read(), c = read();
      a--;
      b--;
      c--;
      int tmp = F::m++;
      ID[i] = tmp;
      F::add_edge(tmp, t, 2);
      F::add_edge(a, tmp, 1);
      F::add_edge(b, tmp, 1);
      F::add_edge(c, tmp, 1);
    } else {
      int l = read(), r = read();
      l--;
      r--;
      int tmp = F::m++;
      ID[i] = tmp;
      F::add_edge(tmp, t, 1);
      add_edge(1, 0, n - 1, l, r, tmp);
      L[i] = l;
      R[i] = r;
    }
  }
  int cost = F::max_flow(s, t);
  cout << cost << endl;
  for (int i = F::head[s]; i != -1; i = E[i].nxt) {
    edge &e = E[i];
    if (e.cap == 0 && e.to < n) {
      ok[e.to] = true;
    }
  }
  for (int qq = 0; qq < q; qq++) {
    if (type[qq] == 2) {
      int x = ID[qq];
      vector<int> v;
      int cnt = 0;
      for (int i = F::head[x]; i != -1; i = E[i].nxt) {
        edge &e = E[i];
        if (cnt == 2) break;
        if (e.to < n) {
          if (e.cap == 1) {
            cout << qq + 1 << " " << e.to + 1 << endl;
            ok[e.to] = false;
            cnt++;
          } else {
            v.push_back(e.to);
          }
        }
      }
      if (cnt == 1) {
        for (int i = 0; i < (int)v.size(); i++) {
          if (ok[v[i]]) {
            cout << qq + 1 << " " << v[i] + 1 << endl;
            ok[v[i]] = false;
            break;
          }
        }
      }
    }
  }
  for (int qq = 0; qq < q; qq++) {
    if (type[qq] == 0) {
      int x = ID[qq];
      for (int i = F::head[x]; i != -1; i = E[i].nxt) {
        edge &e = E[i];
        if (e.cap == 1 && e.to < n && ok[e.to]) {
          cout << qq + 1 << " " << e.to + 1 << endl;
          ok[e.to] = false;
          break;
        }
      }
    }
  }
  for (int i = 0; i < q; i++) {
    if (type[i] == 1) {
      get_ans(1, 0, n - 1, L[i], R[i], ID[i], i);
    }
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < (int)v.size(); i++) {
    int id = v[i].first.second, l = v[i].second.first, r = v[i].second.second;
    for (int j = l; j <= r; j++) {
      if (ok[j]) {
        cout << id + 1 << " " << j + 1 << endl;
        ok[j] = false;
        break;
      }
    }
  }
  return 0;
}