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 Nmax = 30025, Mmax = 310005;
int S, D, weapon[Nmax], K, N, M, Nodes, i;
class Floow {
  vector<int> v[Nmax];
  int go[Mmax], c[Mmax], e = 0, dist[Nmax];
  int taken[Nmax], used[Nmax];
  bool bfs() {
    memset(dist, -1, sizeof(dist));
    queue<int> q;
    dist[S] = 0;
    q.push(S);
    int node, it;
    while (q.size()) {
      node = q.front();
      q.pop();
      for (auto e : v[node]) {
        it = go[e];
        if (c[e] && dist[it] == -1) {
          dist[it] = dist[node] + 1;
          q.push(it);
        }
      }
    }
    return dist[D] != -1;
  }
  int dfs(int node, int flow) {
    if (node == D) return flow;
    if (!flow) return 0;
    int add = 0;
    for (auto it : v[node])
      if (dist[go[it]] == dist[node] + 1 && c[it]) {
        int t = dfs(go[it], min(flow, c[it]));
        c[it] -= t;
        c[it ^ 1] += t;
        flow -= t;
        add += t;
      }
    if (!add) dist[node] = -5;
    return add;
  }

 public:
  void add_edge(int x, int y, int cap) {
    v[x].push_back(e);
    v[y].push_back(e ^ 1);
    go[e ^ 1] = x;
    go[e] = y;
    c[e] = cap;
    c[e ^ 1] = 0;
    e += 2;
  }
  int max_flow() {
    int ans = 0;
    while (bfs()) ans += dfs(S, M);
    return ans;
  }
  void reconstruct() {
    int node, e;
    for (auto it : v[D])
      if (!c[it ^ 1]) {
        for (auto e : v[go[it]])
          if ((e & 1) && !c[e ^ 1]) taken[go[it]] = go[e];
      }
    for (node = N + 1; node <= N + M; ++node) ++used[taken[node]];
    for (node = 1; node <= N; ++node)
      if (weapon[node] == 2 && used[node] == 1) {
        for (auto e : v[node])
          if (!(e & 1) && c[e]) {
            taken[go[e]] = node;
            ++used[node];
            break;
          }
        assert(used[node] == 2);
      }
    int w;
    bool ok;
    for (node = N + 1; node <= N + M; ++node)
      if (taken[node]) {
        w = taken[node];
        if (w > D) {
          ok = 0;
          while (!ok) {
            assert(v[w].size());
            e = v[w][0];
            swap(v[w].front(), v[w].back());
            v[w].pop_back();
            if ((e & 1) && !c[e ^ 1]) {
              w = go[e];
              ok = 1;
            }
          }
        }
        cout << w << ' ' << node - N << '\n';
      }
  }
} graph;
void build_segm(int node, int st, int dr) {
  int i;
  for (i = st; i <= dr; ++i) graph.add_edge(node + D, N + i, 1);
  if (st == dr) {
    if (st == N) Nodes = node + D;
    return;
  }
  build_segm((node << 1), st, ((st + dr) >> 1));
  build_segm(((node << 1) | 1), ((st + dr) >> 1) + 1, dr);
}
void add_segm(int node, int st, int dr, int L, int R) {
  if (L <= st && dr <= R) {
    graph.add_edge(i, node + D, 1);
    return;
  }
  if (L <= ((st + dr) >> 1)) add_segm((node << 1), st, ((st + dr) >> 1), L, R);
  if (((st + dr) >> 1) < R)
    add_segm(((node << 1) | 1), ((st + dr) >> 1) + 1, dr, L, R);
}
int main() {
  cin.sync_with_stdio(false);
  cin >> N >> M;
  S = 0;
  D = N + M + 1;
  int tip, j, x, y;
  for (i = N + 1; i <= N + M; ++i) graph.add_edge(i, D, 1);
  build_segm(1, 1, M);
  for (i = 1; i <= N; ++i) {
    cin >> tip;
    if (tip == 0) {
      graph.add_edge(S, i, 1);
      cin >> K;
      for (j = 1; j <= K; ++j) {
        cin >> x;
        graph.add_edge(i, x + N, 1);
      }
    } else if (tip == 1) {
      graph.add_edge(S, i, 1);
      cin >> x >> y;
      add_segm(1, 1, M, x, y);
    } else if (tip == 2) {
      graph.add_edge(S, i, 2);
      for (j = 1; j <= 3; ++j) {
        cin >> x;
        graph.add_edge(i, x + N, 1);
      }
    }
    weapon[i] = tip;
  }
  cout << graph.max_flow() << '\n';
  graph.reconstruct();
  return 0;
}