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>
#pragma GCC optimize "-O3"
using namespace std;
const int N = 5e3 + 1;
struct Dinitz {
  int n, s, t;
  struct Edge {
    int u, v, c, f;
    Edge(int u = 0, int v = 0, int c = 0) : u(u), v(v), c(c), f(0) {}
  };
  vector<vector<int> > g;
  vector<int> d, ptr;
  vector<Edge> E;
  Dinitz(int _n = 0, int _s = 0, int _t = 0) : n(_n), s(_s), t(_t) {
    g.assign(n + 5, {});
    E.clear();
  }
  void addEdge(int u, int v, int cap) {
    g[u].push_back(E.size());
    E.push_back({u, v, cap});
    g[v].push_back(E.size());
    E.push_back({v, u, 0});
  }
  bool bfs() {
    d.assign(n + 5, -1);
    ptr.assign(n + 5, 0);
    queue<int> q;
    q.push(s);
    d[s] = 0;
    while (q.size()) {
      int u = q.front();
      q.pop();
      for (int i : g[u]) {
        int v = E[i].v;
        if (d[v] < 0 && E[i].c > E[i].f) {
          d[v] = d[u] + 1;
          q.push(v);
        }
      }
    }
    return d[t] != -1;
  }
  int dfs(int u, int flow) {
    if (u == t || !flow) return flow;
    for (int &i = ptr[u]; i < g[u].size(); ++i) {
      int j = g[u][i], v = E[j].v;
      if (d[v] != d[u] + 1) continue;
      if (E[j].c <= E[j].f) continue;
      int nxt = dfs(v, min(flow, E[j].c - E[j].f));
      if (nxt) {
        E[j].f += nxt;
        E[j ^ 1].f -= nxt;
        return nxt;
      }
    }
    return 0;
  }
  int calc() {
    while (bfs())
      while (dfs(s, N))
        ;
    int res = 0;
    for (int i : g[s]) res += E[i].f;
    return res;
  }
  vector<int> path;
  void trace(int u) {
    path.push_back(u);
    if (u == t) return;
    for (int i : g[u]) {
      int v = E[i].v;
      if (E[i].f > 0) {
        E[i].f--;
        trace(v);
        return;
      }
    }
  }
  vector<vector<int> > work() {
    vector<vector<int> > res;
    while (1) {
      path.clear();
      trace(s);
      if (path.size() == 1) break;
      res.push_back(path);
    }
    return res;
  }
} W;
int n, m, tot;
int l[N], r[N], op[N];
int T[N << 2];
int fl[N], ok[N];
vector<int> g[N];
void init(int i, int l, int r) {
  if (l == r) {
    T[i] = l + n;
    return;
  }
  init(i << 1, l, (l + r) / 2);
  init(i << 1 | 1, (l + r) / 2 + 1, r);
  T[i] = ++tot;
}
void _upd(int i, int l, int r, int L, int R, int u) {
  if (L <= l && r <= R) {
    W.addEdge(u, T[i], 1);
    return;
  }
  if (L <= (l + r) / 2) _upd(i << 1, l, (l + r) / 2, L, R, u);
  if (R > (l + r) / 2) _upd(i << 1 | 1, (l + r) / 2 + 1, r, L, R, u);
}
void _add(int i, int l, int r) {
  if (l == r) {
    if (!fl[l]) W.addEdge(T[i], tot, 1);
    return;
  }
  W.addEdge(T[i], T[i << 1], N);
  W.addEdge(T[i], T[i << 1 | 1], N);
  _add(i << 1, l, (l + r) / 2);
  _add(i << 1 | 1, (l + r) / 2 + 1, r);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  tot = n + m;
  for (int i = 1; i <= n; ++i) {
    cin >> op[i];
    if (op[i] == 0) {
      int sz;
      cin >> sz;
      while (sz--) {
        int x;
        cin >> x;
        g[i].push_back(x);
      }
    }
    if (op[i] == 1) cin >> l[i] >> r[i];
    if (op[i] == 2) {
      int sz = 3;
      ++tot;
      while (sz--) {
        int x;
        cin >> x;
        g[i].push_back(x);
        fl[x] = 1;
      }
    }
  }
  init(1, 1, m);
  W = Dinitz(++tot, 0, tot);
  int now = n + m;
  for (int i = 1; i <= n; ++i) {
    W.addEdge(0, i, 1);
    if (op[i] == 0)
      for (int u : g[i]) W.addEdge(i, u + n, 1);
    if (op[i] == 1) _upd(1, 1, m, l[i], r[i], i);
    if (op[i] == 2) {
      W.addEdge(++now, tot, 1);
      for (int u : g[i]) W.addEdge(u + n, now, 1);
    }
  }
  _add(1, 1, m);
  W.calc();
  vector<vector<int> > res = W.work();
  vector<pair<int, int> > ans;
  for (auto vec : res) {
    int u = vec[1], v = vec[vec.size() - 2] - n;
    if (v > m) v = vec[vec.size() - 3] - n;
    ans.push_back({u, v});
    ok[v] = 1;
  }
  for (int i = 1; i <= n; ++i)
    if (op[i] == 2) {
      int sz = 2;
      for (int u : g[i])
        if (sz && !ok[u]) {
          ans.push_back({i, u});
          --sz;
        }
    }
  cout << ans.size() << "\n";
  for (pair<int, int> F : ans) cout << F.first << " " << F.second << "\n";
}