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>
template <class T, class U>
inline bool smin(T &x, const U &y) {
  return y < x ? x = y, 1 : 0;
}
template <class T, class U>
inline bool smax(T &x, const U &y) {
  return x < y ? x = y, 1 : 0;
}
using LL = long long;
using PII = std::pair<int, int>;
template <class F = int>
class Graph {
 public:
  struct Edge {
    int v;
    F w;
  };
  Graph(int n) : e(), g(n) {}
  std::vector<Edge> e;
  std::vector<std::vector<int>> g;
  void AddEdge(int x, int y, F z) {
    g[x].push_back(e.size()), e.push_back({y, z});
    g[y].push_back(e.size()), e.push_back({x, 0});
  }
  F MaxFlow(int s_, int t_) {
    d.resize(g.size());
    cur.resize(g.size());
    s = s_, t = t_;
    F f = 0;
    while (bfs()) {
      std::fill(cur.begin(), cur.end(), 0);
      f += dfs(s, std::numeric_limits<F>().max());
    }
    return f;
  }

 private:
  std::vector<int> d, cur;
  int s, t;
  int bfs() {
    static int q[1000005], l, r;
    std::fill(d.begin(), d.end(), -1);
    q[l = r = 1] = s, d[s] = 0;
    while (l <= r) {
      int x = q[l++];
      for (int i : g[x]) {
        if (e[i].w && !~d[e[i].v]) {
          d[q[++r] = e[i].v] = d[x] + 1;
        }
      }
    }
    return ~d[t];
  }
  F dfs(int x, F flow) {
    if (x == t || !flow) return flow;
    F used = 0;
    for (; cur[x] < g[x].size(); cur[x]++) {
      int i = g[x][cur[x]], y = e[i].v;
      if (!e[i].w || d[y] != d[x] + 1) continue;
      F f = dfs(y, std::min(flow - used, e[i].w));
      e[i].w -= f, e[i ^ 1].w += f, used += f;
      if (flow == used) return used;
    }
    if (!used) d[x] = -1;
    return used;
  }
};
Graph<int> *g;
struct Node {
  int ls, rs, leaf;
} t[666666];
int n, m, cnt, id[5005];
void build(int &o, int l, int r) {
  g->g.emplace_back();
  t[o = ++cnt] = {0, 0, 0};
  if (l == r) {
    id[l] = o;
    t[o].leaf = l;
    return;
  }
  int m = l + r >> 1;
  build(t[o].ls, l, m);
  build(t[o].rs, m + 1, r);
  g->AddEdge(o, t[o].ls, INT_MAX);
  g->AddEdge(o, t[o].rs, INT_MAX);
}
void link(int o, int l, int r, int x, int y, int s) {
  if (x <= l && r <= y) {
    g->AddEdge(s, o, INT_MAX);
    return;
  }
  int m = l + r >> 1;
  if (x <= m) link(t[o].ls, l, m, x, y, s);
  if (y > m) link(t[o].rs, m + 1, r, x, y, s);
}
int tp[5005], a[5005][3], bel[5005];
int f[5005];
void dfs(int x, int p) {
  if (!f[p]) return;
  if (x <= cnt && t[x].leaf) {
    bel[t[x].leaf] = p;
    f[p]--;
    return;
  }
  for (int i : g->g[x]) {
    int y = g->e[i].v;
    if (!y || y > cnt || !g->e[i ^ 1].w) continue;
    g->e[i].w++;
    g->e[i ^ 1].w--;
    dfs(y, p);
    if (!f[p]) return;
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cin >> n >> m;
  g = new Graph<int>(1);
  int root;
  build(root, 1, m);
  g->g.resize(cnt + n + 2);
  int s = 0, t = cnt + n + 1;
  for (int i = 1; i <= m; i++) g->AddEdge(id[i], t, 1);
  for (int i = 1; i <= n; i++) {
    std::cin >> tp[i];
    switch (tp[i]) {
      case 0:
        g->AddEdge(s, i + cnt, 1);
        int k, x;
        std::cin >> k;
        while (k--) {
          std::cin >> x;
          g->AddEdge(i + cnt, id[x], 1);
        }
        break;
      case 1:
        g->AddEdge(s, i + cnt, 1);
        int l, r;
        std::cin >> l >> r;
        link(root, 1, m, l, r, i + cnt);
        break;
      case 2:
        g->AddEdge(s, i + cnt, 2);
        std::cin >> a[i][0] >> a[i][1] >> a[i][2];
        for (int j = 0; j < 3; j++) g->AddEdge(i + cnt, id[a[i][j]], 1);
        break;
    }
  }
  int ans = g->MaxFlow(s, t);
  std::cout << ans << "\n";
  for (int i = 1; i <= n; i++) {
    int j = g->g[i + cnt][0];
    assert(g->e[j].v == s);
    if (!g->e[j].w) continue;
    f[i] = g->e[j].w;
    dfs(i + cnt, i);
  }
  for (int i = 1; i <= n; i++) {
    int j = g->g[i + cnt][0];
    if (tp[i] == 2 && g->e[j].w == 1) {
      bel[a[i][bel[a[i][0]] == i]] = i;
    }
  }
  for (int i = 1; i <= m; i++) {
    if (bel[i]) std::cout << bel[i] << " " << i << "\n";
  }
  return 0;
}