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;
int n, m;
const int sz = 1 << 13;
vector<int> gos[5001];
int rev[5001];
template <class T>
class Dinic {
  struct _edge {
    int x, y;
    T c, rc;
    _edge(int x, int y, T c, T rc) : x(x), y(y), c(c), rc(rc) {}
  };
  int s, e;
  int n;
  vector<T> nowFlow;
  vector<vector<int>> edge;
  vector<_edge> es;
  vector<int> dist;
  vector<int> it;
  T inf;
  int bfs() {
    for (int i = 0; i < n; ++i) dist[i] = -1;
    queue<int> q;
    dist[s] = 0;
    q.push(s);
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      for (int i : edge[x]) {
        if (i < 0) {
          i = ~i;
          if (dist[es[i].x] != -1) continue;
          if (es[i].rc > 0) {
            dist[es[i].x] = dist[x] + 1;
            q.push(es[i].x);
          }
        } else {
          if (dist[es[i].y] != -1) continue;
          if (es[i].c > 0) {
            dist[es[i].y] = dist[x] + 1;
            q.push(es[i].y);
          }
        }
      }
    }
    return dist[e] != -1;
  }
  T dfs(int x, T f) {
    if (x == e) return f;
    for (int &i = it[x]; i < edge[x].size(); ++i) {
      int y;
      T c;
      if (edge[x][i] < 0)
        y = es[~edge[x][i]].x, c = es[~edge[x][i]].rc;
      else
        y = es[edge[x][i]].y, c = es[edge[x][i]].c;
      if (dist[x] + 1 != dist[y]) continue;
      if (c == 0) continue;
      c = dfs(y, min(f, c));
      if (c > 0) {
        if (edge[x][i] < 0) {
          es[~edge[x][i]].c += c;
          es[~edge[x][i]].rc -= c;
          nowFlow[~edge[x][i]] -= c;
        } else {
          es[edge[x][i]].c -= c;
          es[edge[x][i]].rc += c;
          nowFlow[edge[x][i]] += c;
        }
        return c;
      }
    }
    return 0;
  }
  int matchdfs(int x) {
    if (::n + ::sz <= x && x < ::n + ::sz + ::m) return x - ::n - sz + 1;
    for (int &i = it[x]; i < edge[x].size(); ++i) {
      int y;
      T c;
      if (edge[x][i] < 0)
        y = es[~edge[x][i]].x, c = -nowFlow[~edge[x][i]];
      else
        y = es[edge[x][i]].y, c = nowFlow[edge[x][i]];
      if (c <= 0) continue;
      if (edge[x][i] < 0)
        ++nowFlow[~edge[x][i]];
      else
        --nowFlow[edge[x][i]];
      return matchdfs(y);
    }
    return 0;
  }

 public:
  void init(int N) {
    n = N;
    inf = 0;
    edge.clear();
    edge.resize(n);
    dist.resize(n);
    it.resize(n);
    nowFlow.clear();
    es.clear();
  }
  int addEdge(int x, int y, T C, T RC) {
    inf = max(inf, C + RC);
    int idx = es.size();
    es.emplace_back(x, y, C, RC);
    nowFlow.push_back(0);
    edge[x].push_back(idx);
    edge[y].push_back(~idx);
    return idx;
  }
  T findMaximumFlow(int source, int sink) {
    s = source;
    e = sink;
    T flow = 0;
    while (bfs()) {
      for (int i = 0; i < n; ++i) it[i] = 0;
      while (1) {
        T ret = dfs(s, inf);
        if (ret == 0) break;
        flow += ret;
      }
    }
    return flow;
  }
  T getFlow(int idx) { return nowFlow[idx]; }
  void findMatching() {
    for (int i = 0; i < n; ++i) it[i] = 0;
    for (int i = 1; i <= ::n; ++i) {
      int r = matchdfs(i);
      if (r) {
        gos[i].push_back(r);
        rev[r] = i;
        --i;
      }
    }
  }
};
struct weapon {
  int type;
  int l, r;
  vector<int> ps;
  void scan() {
    cin >> type;
    if (type == 0) {
      int k, x;
      cin >> k;
      for (int i = 0; i < k; ++i) {
        cin >> x;
        ps.push_back(x);
      }
    } else if (type == 1) {
      cin >> l >> r;
    } else {
      for (int i = 0; i < 3; ++i) {
        int x;
        cin >> x;
        ps.push_back(x);
      }
    }
  }
} wps[5001];
Dinic<int> dinic;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    wps[i].scan();
  }
  dinic.init(n + sz + m + 10);
  int S = 0, E = n + sz + m + 9;
  for (int i = sz + m - 1; i > 1; --i) {
    dinic.addEdge(n + (i >> 1), n + i, m, 0);
  }
  for (int i = 1; i <= n; ++i) {
    dinic.addEdge(S, i, wps[i].type == 2 ? 2 : 1, 0);
    if (wps[i].type == 1) {
      int s = sz + wps[i].l - 1, e = sz + wps[i].r - 1;
      while (s <= e) {
        if ((s & 1) == 1) dinic.addEdge(i, n + (s++), 1, 0);
        if ((e & 1) == 0) dinic.addEdge(i, n + (e--), 1, 0);
        s >>= 1;
        e >>= 1;
      }
    } else {
      for (int j : wps[i].ps) dinic.addEdge(i, n + sz + j - 1, 1, 0);
    }
  }
  for (int i = 0; i < m; ++i) {
    dinic.addEdge(n + sz + i, E, 1, 0);
  }
  int ans = dinic.findMaximumFlow(S, E);
  printf("%d\n", ans);
  dinic.findMatching();
  for (int i = 1; i <= n; ++i) {
    if (wps[i].type != 2) continue;
    if (gos[i].size() != 1) continue;
    for (int j = 0; j < 3; ++j) {
      if (gos[i][0] == wps[i].ps[j]) continue;
      gos[rev[wps[i].ps[j]]].clear();
      rev[wps[i].ps[j]] = i;
      gos[i].push_back(wps[i].ps[j]);
      break;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j : gos[i]) {
      printf("%d %d\n", i, j);
    }
  }
}