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;
struct edge {
  int to, rev;
  long long f, cap, id;
};
struct Dinic {
  int nodes, src, dst;
  vector<int> dist, q, work;
  vector<vector<edge>> g;
  Dinic(int x) : nodes(x), g(x), dist(x), q(x), work(x) {}
  void add_edge(int s, int t, long long cap) {
    g[s].push_back((edge){t, ((int)g[t].size()), 0, cap});
    g[t].push_back((edge){s, ((int)g[s].size()) - 1, 0, 0});
  }
  bool dinic_bfs() {
    fill(dist.begin(), dist.end(), -1);
    dist[src] = 0;
    int qt = 0;
    q[qt++] = src;
    for (int qh = 0; qh < qt; qh++) {
      int u = q[qh];
      for (int i = 0; i < ((int)g[u].size()); i++) {
        edge &e = g[u][i];
        int v = g[u][i].to;
        if (dist[v] < 0 && e.f < e.cap) dist[v] = dist[u] + 1, q[qt++] = v;
      }
    }
    return dist[dst] >= 0;
  }
  long long dinic_dfs(int u, long long f) {
    if (u == dst) return f;
    for (int &i = work[u]; i < ((int)g[u].size()); i++) {
      edge &e = g[u][i];
      if (e.cap <= e.f) continue;
      int v = e.to;
      if (dist[v] == dist[u] + 1) {
        long long df = dinic_dfs(v, min(f, e.cap - e.f));
        if (df > 0) {
          e.f += df;
          g[v][e.rev].f -= df;
          return df;
        }
      }
    }
    return 0;
  }
  long long max_flow(int _src, int _dst) {
    src = _src;
    dst = _dst;
    long long result = 0;
    while (dinic_bfs()) {
      fill(work.begin(), work.end(), 0);
      while (long long delta = dinic_dfs(src, 1e9)) result += delta;
    }
    return result;
  }
};
int n, m, nodes, N;
void build(int k, int s, int e, Dinic &d) {
  if (s + 1 == e) {
    d.add_edge(k + nodes, n + s, 1e9);
    return;
  }
  int med = (s + e) / 2;
  d.add_edge(k + nodes, 2 * k + nodes, 1e9);
  d.add_edge(k + nodes, 2 * k + 1 + nodes, 1e9);
  build(2 * k, s, med, d);
  build(2 * k + 1, med, e, d);
}
void connect(int k, int s, int e, int a, int b, int v, Dinic &d) {
  if (s >= b || e <= a) return;
  if (s >= a && e <= b) {
    d.add_edge(v, k + nodes, 1);
    return;
  }
  int med = (s + e) / 2;
  connect(2 * k, s, med, a, b, v, d);
  connect(2 * k + 1, med, e, a, b, v, d);
}
int main() {
  cin >> n >> m;
  nodes = n + m;
  N = n + m + 6 * m;
  int types[n];
  Dinic d(N + 2);
  build(1, 0, m, d);
  for (int i = 0; i < m; i++) d.add_edge(n + i, N + 1, 1);
  for (int i = 0; i < n; i++) {
    int t, k, l, r, a, b, c;
    cin >> t;
    if (t == 0) {
      d.add_edge(N, i, 1);
      cin >> k;
      for (int j = 0; j < k; j++) {
        int x;
        cin >> x;
        d.add_edge(i, n + x - 1, 1);
      }
    }
    if (t == 1) {
      cin >> l >> r;
      d.add_edge(N, i, 1);
      connect(1, 0, m, l - 1, r, i, d);
    }
    if (t == 2) {
      d.add_edge(N, i, 2);
      cin >> a >> b >> c;
      a--, b--, c--;
      d.add_edge(i, n + a, 1);
      d.add_edge(i, n + b, 1);
      d.add_edge(i, n + c, 1);
    }
    types[i] = t;
  }
  cout << d.max_flow(N, N + 1) << '\n';
  int killed[m];
  memset(killed, -1, sizeof(killed));
  vector<vector<edge>> &g = d.g;
  for (int i = 0; i < n; i++) {
    int c = 0;
    queue<int> q;
    q.push(i);
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      for (auto &e : g[x])
        if (e.cap && e.f) {
          if (e.to >= n && e.to < n + m)
            killed[e.to - n] = i, c++;
          else {
            q.push(e.to);
            e.f--;
            if (types[i] != 2) break;
          }
        }
    }
    if (c == 1 && types[i] == 2) {
      for (auto &e : g[i])
        if (e.cap && !e.f) {
          killed[e.to - n] = i;
          break;
        }
    }
  }
  for (int i = 0; i < m; i++)
    if (killed[i] != -1) cout << killed[i] + 1 << " " << i + 1 << '\n';
  return 0;
}