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>
#pragma GCC optimize("Ofast")
using namespace std;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
const int N = 5005;
int n, m, ty[N];
struct FlowEdge {
  int v, u;
  long long cap, flow = 0;
  FlowEdge(int v, int u, long long cap, long long flow)
      : v(v), u(u), cap(cap), flow(flow) {}
};
struct Dinic {
  const long long flow_inf = 1e18;
  vector<FlowEdge> edges;
  vector<vector<int>> adj;
  int n, m = 0;
  int s, t;
  vector<int> level, ptr;
  queue<int> q;
  Dinic(int n, int s, int t) : n(n), s(s), t(t) {
    adj.resize(n);
    level.resize(n);
    ptr.resize(n);
  }
  void add_edge(int v, int u, long long cap) {
    edges.emplace_back(v, u, cap, 0);
    edges.emplace_back(u, v, cap, cap);
    adj[v].push_back(m);
    adj[u].push_back(m + 1);
    m += 2;
  }
  bool bfs() {
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (int id : adj[v]) {
        if (edges[id].cap - edges[id].flow < 1) continue;
        if (level[edges[id].u] != -1) continue;
        level[edges[id].u] = level[v] + 1;
        q.push(edges[id].u);
      }
    }
    return level[t] != -1;
  }
  long long dfs(int v, long long pushed) {
    if (pushed == 0) return 0;
    if (v == t) return pushed;
    for (int &cid = ptr[v]; cid < (int)adj[v].size(); cid++) {
      int id = adj[v][cid];
      int u = edges[id].u;
      if (level[v] + 1 != level[u] || edges[id].cap - edges[id].flow < 1)
        continue;
      long long tr = dfs(u, min(pushed, edges[id].cap - edges[id].flow));
      if (tr == 0) continue;
      edges[id].flow += tr;
      edges[id ^ 1].flow -= tr;
      return tr;
    }
    return 0;
  }
  long long flow() {
    long long f = 0;
    while (true) {
      fill(level.begin(), level.end(), -1);
      level[s] = 0;
      q.push(s);
      if (!bfs()) break;
      fill(ptr.begin(), ptr.end(), 0);
      while (long long pushed = dfs(s, flow_inf)) {
        f += pushed;
      }
    }
    return f;
  }
};
int ans = 0;
void build(int i, int l, int r, Dinic &F) {
  if (l == r) {
    F.add_edge(i, (4 * m + (l)), N);
    return;
  }
  int m = (l + r) / 2;
  F.add_edge(i, 2 * i + 1, N);
  F.add_edge(i, 2 * i + 2, N);
  build(2 * i + 1, l, m, F);
  build(2 * i + 2, m + 1, r, F);
}
void upd(int i, int l, int r, int L, int R, int w, Dinic &F) {
  if (r < L || R < l) return;
  if (L <= l && r <= R) {
    F.add_edge((5 * m + (w)), i, 1);
    return;
  }
  int m = (l + r) / 2;
  upd(2 * i + 1, l, m, L, R, w, F);
  upd(2 * i + 2, m + 1, r, L, R, w, F);
}
bool used[N];
int cnt[N];
int assign(int u, Dinic &F) {
  if (u >= (4 * m)) {
    return u - (4 * m + (0));
  }
  for (int i : F.adj[u]) {
    if (F.edges[i].u > u && F.edges[i].flow > 0) {
      F.edges[i].flow--;
      int x = assign(F.edges[i].u, F);
      if (x != -1) return x;
    }
  }
  return -1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  Dinic F = Dinic((5 * m + n + 1) + 1, (4 * m), (5 * m + n + 1));
  build(0, 1, m, F);
  for (int i = (1); i < (n + 1); i++) {
    cin >> ty[i];
    if (ty[i] == 0) {
      int k;
      cin >> k;
      while (k--) {
        int s;
        cin >> s;
        F.add_edge((5 * m + (i)), (4 * m + (s)), 1);
      }
      F.add_edge((4 * m), (5 * m + (i)), 1);
    } else if (ty[i] == 1) {
      int l, r;
      cin >> l >> r;
      upd(0, 1, m, l, r, i, F);
      F.add_edge((4 * m), (5 * m + (i)), 1);
    } else {
      int a, b, c;
      cin >> a >> b >> c;
      used[a] = used[b] = used[c] = true;
      ans += 2;
      F.add_edge((4 * m + (a)), (5 * m + (i)), 1);
      F.add_edge((4 * m + (b)), (5 * m + (i)), 1);
      F.add_edge((4 * m + (c)), (5 * m + (i)), 1);
      F.add_edge((5 * m + (i)), (5 * m + n + 1), 1);
    }
  }
  for (int i = (1); i < (m + 1); i++) {
    if (!used[i]) {
      F.add_edge((4 * m + (i)), (5 * m + n + 1), 1);
    }
  }
  ans += F.flow();
  cout << ans << '\n';
  for (int w = (1); w < (n + 1); w++) {
    for (int i : F.adj[(5 * m + (w))]) {
      int s = F.edges[i].u - (4 * m + (0));
      if (ty[w] == 1) {
        if (F.edges[i].u < (4 * m) && F.edges[i].flow == 1) {
          int sh = assign(F.edges[i].u, F);
          assert(sh != -1);
          cout << w << ' ' << sh << '\n';
        }
      } else if (s >= 1 && s <= m && F.edges[i].flow == 1) {
        if (ty[w] == 0 || cnt[w] < 2) {
          cnt[w]++;
          cout << w << ' ' << s << '\n';
        }
      }
    }
  }
}