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;
#pragma warning(disable : 4996)
struct E {
  int to, i;
};
const int N = 2e4 + 5, M = 1e6, INF = 1e9, S = N - 2, T = N - 1;
vector<E> g[N];
int cp[M], fl[M], lc[N], rc[N], d[N], p[N], killedBy[N], ct[N];
int ce = 0, cv = 0;
void addEdge(int a, int b, int c) {
  cp[ce] = c;
  g[a].push_back({b, ce++});
  cp[ce] = 0;
  g[b].push_back({a, ce++});
}
void build(int v, int L, int R) {
  if (L == R) {
    addEdge(v, L, 1);
  } else {
    lc[v] = cv;
    rc[v] = cv + 1;
    int m = (L + R) >> 1;
    addEdge(v, lc[v], INF);
    addEdge(v, rc[v], INF);
    cv += 2;
    build(lc[v], L, m);
    build(rc[v], m + 1, R);
  }
}
void que(int l, int r, int from, int v, int L, int R) {
  if (l > r) return;
  if (L == l && R == r) {
    addEdge(from, v, 1);
  } else {
    int m = (L + R) >> 1;
    que(l, min(m, r), from, lc[v], L, m);
    que(max(m + 1, l), r, from, rc[v], m + 1, R);
  }
}
bool bfs() {
  memset(d, -1, sizeof(d));
  d[S] = 0;
  queue<int> q;
  q.push(S);
  while (!q.empty()) {
    int node = q.front();
    q.pop();
    for (E e : g[node]) {
      if (d[e.to] == -1 && cp[e.i] > fl[e.i]) {
        d[e.to] = d[node] + 1;
        q.push(e.to);
      }
    }
  }
  return d[T] != -1;
}
int dfs(int node, int flow) {
  if (node == T) return flow;
  for (int& i = p[node]; i < g[node].size(); i++) {
    E& e = g[node][i];
    if (d[e.to] == d[node] + 1 && cp[e.i] > fl[e.i]) {
      int ret = dfs(e.to, min(flow, cp[e.i] - fl[e.i]));
      if (ret) {
        fl[e.i] += ret;
        fl[e.i ^ 1] -= ret;
        return ret;
      }
    }
  }
  return 0;
}
int maxFlow() {
  int flow = 0;
  while (bfs()) {
    memset(p, 0, sizeof(p));
    int ret;
    while ((ret = dfs(S, INF))) {
      flow += ret;
    }
  }
  return flow;
}
vector<vector<int>> t3;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) addEdge(i, T, 1);
  cv = n + m;
  int root = cv;
  cv++;
  build(root, 0, m - 1);
  for (int i = m; i < n + m; i++) {
    int type;
    cin >> type;
    if (type == 0) {
      addEdge(S, i, 1);
      int k;
      cin >> k;
      while (k--) {
        int x;
        cin >> x;
        x--;
        addEdge(i, x, 1);
      }
    } else if (type == 1) {
      addEdge(S, i, 1);
      int l, r;
      cin >> l >> r;
      l--, r--;
      que(l, r, i, root, 0, m - 1);
    } else {
      addEdge(S, i, 2);
      int a, b, c;
      cin >> a >> b >> c;
      a--, b--, c--;
      addEdge(i, a, 1);
      addEdge(i, b, 1);
      addEdge(i, c, 1);
      t3.push_back({a, b, c, i - m});
    }
  }
  cout << maxFlow() << "\n";
  memset(killedBy, -1, sizeof(killedBy));
  for (int i = 0; i < m; i++) {
    int x = i;
    bool alive = true;
    for (E e : g[x]) {
      if (fl[e.i] < 0) {
        alive = false;
        break;
      }
    }
    if (alive) continue;
    while (x < m || x >= n + m) {
      for (E e : g[x]) {
        if (fl[e.i] < 0) {
          fl[e.i]++;
          x = e.to;
          break;
        }
      }
    }
    killedBy[i] = x - m;
  }
  for (int i = 0; i < m; i++) {
    if (killedBy[i] != -1) {
      ct[killedBy[i]]++;
    }
  }
  for (auto x : t3) {
    if (ct[x[3]] == 1) {
      for (int i = 0; i < 3; i++) {
        if (killedBy[x[i]] != x[3]) {
          killedBy[x[i]] = x[3];
          break;
        }
      }
    }
  }
  for (int i = 0; i < m; i++) {
    if (killedBy[i] != -1) {
      cout << killedBy[i] + 1 << " " << i + 1 << "\n";
    }
  }
  return 0;
}