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 INF = numeric_limits<int>::max() / 2;
int n, m;
int tot;
int posSeg[100005], idinSeg[5005], inv[100005];
vector<int> target[5005], vert[5005];
bool omg[5005], byOmg[5005];
struct Dinitz {
  struct Edge {
    int u, v, f;
  };
  vector<Edge> E;
  vector<int> adj[100005];
  int dis[100005], ptr[100005];
  int S, T, Nodes;
  void add(int u, int v, int w) {
    E.push_back({u, v, w});
    E.push_back({v, u, 0});
    adj[u].push_back((int)E.size() - 2);
    adj[v].push_back((int)E.size() - 1);
  }
  bool bfs() {
    for (int i = 0; i <= Nodes; i++) dis[i] = INF;
    dis[S] = 0;
    queue<int> q;
    q.push(S);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (auto id : adj[u]) {
        int v = E[id].v, f = E[id].f;
        if (f and dis[v] > dis[u] + 1) {
          dis[v] = dis[u] + 1;
          q.push(v);
        }
      }
    }
    return dis[T] < INF;
  }
  int dfs(int u, int flow) {
    if (u == T or !flow) return flow;
    for (int &i = ptr[u]; i < (int)adj[u].size(); i++) {
      int id = adj[u][i];
      int v = E[id].v, f = E[id].f;
      if (dis[v] == dis[u] + 1) {
        int newflow = dfs(v, min(flow, f));
        if (newflow) {
          E[id].f -= newflow;
          E[id ^ 1].f += newflow;
          return newflow;
        }
      }
    }
    return 0;
  }
  int maxflow() {
    int ret = 0;
    while (bfs()) {
      for (int i = 0; i <= Nodes; i++) ptr[i] = 0;
      while (int flow = dfs(S, INF)) ret += flow;
    }
    return ret;
  }
  int traverse(int u) {
    for (auto id : adj[u]) {
      if (E[id].v != T and E[id].v > u and E[id ^ 1].f) {
        E[id ^ 1].f--;
        return traverse(E[id].v);
      }
    }
    return u;
  }
} Flow;
void build(int i, int l, int r) {
  posSeg[i] = ++tot;
  if (l == r) {
    idinSeg[l] = i;
    inv[posSeg[i]] = l;
    return;
  }
  int mid = (l + r) >> 1;
  build(i << 1, l, mid);
  build(i << 1 | 1, mid + 1, r);
  Flow.add(posSeg[i], posSeg[i << 1], INF);
  Flow.add(posSeg[i], posSeg[i << 1 | 1], INF);
}
void addSeg(int i, int l, int r, int id, int L, int R) {
  if (R < l or r < L or L > R) return;
  if (L <= l and r <= R) {
    Flow.add(id, posSeg[i], INF);
    return;
  }
  int mid = (l + r) >> 1;
  addSeg(i << 1, l, mid, id, L, R);
  addSeg(i << 1 | 1, mid + 1, r, id, L, R);
}
void addSeg(int id, int L, int R) { addSeg(1, 1, m, id, L, R); }
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  tot = n;
  build(1, 1, m);
  Flow.S = 0;
  Flow.T = Flow.Nodes = ++tot;
  for (int i = 1; i <= m; i++) {
    Flow.add(posSeg[idinSeg[i]], Flow.T, 1);
  }
  for (int i = 1; i <= n; i++) {
    int type;
    cin >> type;
    Flow.add(0, i, (type == 2 ? 2 : 1));
    if (type == 2) {
      omg[i] = true;
    }
    if (!type) {
      int sz;
      cin >> sz;
      for (int j = 1; j <= sz; j++) {
        int id;
        cin >> id;
        addSeg(i, id, id);
      }
    } else if (type == 1) {
      int l, r;
      cin >> l >> r;
      addSeg(i, l, r);
    } else {
      for (int j = 0; j < 3; j++) {
        int id;
        cin >> id;
        addSeg(i, id, id);
        vert[i].push_back(id);
      }
    }
  }
  int ans = Flow.maxflow();
  for (int i = 1, id; i <= n; i++) {
    while ((id = Flow.traverse(i)) != i) target[i].push_back(inv[id]);
    if (omg[i])
      for (auto x : target[i]) byOmg[x] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (omg[i] and (int) target[i].size() == 1) {
      for (auto x : vert[i]) {
        if (!byOmg[x]) {
          byOmg[x] = true;
          target[i].push_back(x);
          break;
        }
      }
    }
  }
  cout << ans << '\n';
  for (int i = 1; i <= n; i++) {
    for (auto id : target[i]) {
      if (!omg[i] and byOmg[id]) continue;
      cout << i << ' ' << id << '\n';
    }
  }
}