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;
map<int, int> pos;
struct DINIC {
  static const int maxn = 15005, inf = 0x3f3f3f3f;
  struct edge {
    int u, v, c, rev;
    edge(int _u, int _v, int _c) : u(_u), v(_v), c(_c), rev(0) {}
    int go(int i) { return u ^ v ^ i; }
    int cap(int i) { return i == u ? c : rev; }
    void flow(int i, int f) {
      if (i == v) f *= -1;
      c -= f, rev += f;
    }
  };
  vector<edge> e;
  vector<int> g[maxn];
  int d[maxn], it[maxn], n, s, t;
  void init(int _n, int _s, int _t) { n = _n, s = _s, t = _t; }
  void link(int x, int y, int c = inf) {
    g[x].push_back(e.size()), g[y].push_back(e.size()), e.emplace_back(x, y, c);
  }
  bool bfs() {
    memset(d, inf, sizeof(d));
    queue<int> q;
    d[s] = 0, q.push(s);
    while (!q.empty()) {
      int i = q.front();
      q.pop();
      for (int j : g[i])
        if (e[j].cap(i) && d[e[j].go(i)] == inf)
          d[e[j].go(i)] = d[i] + 1, q.push(e[j].go(i));
    }
    return d[t] != inf;
  }
  int dfs(int i, int f) {
    if (i == t) return f;
    for (int &ii = it[i]; ii < g[i].size(); ++ii) {
      edge &j = e[g[i][ii]];
      if (j.cap(i) && d[j.go(i)] == d[i] + 1) {
        int ret = dfs(j.go(i), min(f, j.cap(i)));
        if (ret) return j.flow(i, ret), ret;
      }
    }
    return 0;
  }
  int flow() {
    int ans = 0;
    while (bfs()) {
      memset(it, 0, sizeof(it));
      int ret;
      while (ret = dfs(s, inf)) ans += ret;
    }
    return ans;
  }
  vector<vector<int>> track(int _n) {
    vector<vector<int>> v(n);
    for (int i = n - 1; i > 1; --i)
      for (int j : g[i])
        if (e[j].rev && i == e[j].u) {
          if (e[j].v == t)
            v[i].push_back(pos[i]);
          else
            for (int ii = 0; ii < e[j].rev; ++ii)
              v[i].push_back(v[e[j].v].back()), v[e[j].v].pop_back();
        }
    return vector<vector<int>>(v.begin() + 2, v.begin() + 2 + _n);
  }
} flow;
int _id;
struct seg {
  int l, r, v;
  seg *ch[2]{};
  seg(int _l, int _r) : l(_l), r(_r) {
    v = _id++;
    if (l < r - 1) {
      ch[0] = new seg(l, l + r >> 1), ch[1] = new seg(l + r >> 1, r);
      flow.link(v, ch[0]->v), flow.link(v, ch[1]->v);
    } else
      flow.link(v, 1, 1), pos[v] = l;
  }
  void link(int _l, int _r, int i) {
    if (_l <= l && r <= _r) {
      flow.link(i, v, 1);
      return;
    }
    int m = l + r >> 1;
    if (_l < m) ch[0]->link(_l, _r, i);
    if (m < _r) ch[1]->link(_l, _r, i);
  }
};
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n, m, s = _id++, t = _id++;
  cin >> n >> m;
  int id[n];
  for (int &i : id) i = _id++;
  seg rt(0, m);
  flow.init(_id, s, t);
  vector<array<int, 4>> v3;
  for (int i = 0; i < n; ++i) {
    int ty;
    cin >> ty;
    if (ty == 0) {
      int sz;
      cin >> sz;
      while (sz--) {
        int x;
        cin >> x;
        rt.link(x - 1, x, id[i]);
      }
      flow.link(s, id[i], 1);
    } else if (ty == 1) {
      int x, y;
      cin >> x >> y;
      rt.link(x - 1, y, id[i]);
      flow.link(s, id[i], 1);
    } else {
      int x, y, z;
      cin >> x >> y >> z;
      --x, --y, --z;
      v3.push_back({i, x, y, z});
      rt.link(x, x + 1, id[i]), rt.link(y, y + 1, id[i]),
          rt.link(z, z + 1, id[i]);
      flow.link(s, id[i], 2);
    }
  }
  cout << flow.flow() << '\n';
  vector<vector<int>> ans = flow.track(n);
  vector<int> v(m, -1);
  for (auto i : v3)
    if (ans[i[0]].size() == 1) v[ans[i[0]][0] == i[1] ? i[2] : i[1]] = i[0];
  for (int i = 0; i < n; ++i)
    for (int j : ans[i]) {
      cout << (v[j] == -1 ? i + 1 : v[j] + 1) << ' ' << j + 1 << '\n';
    }
}