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 MOD = (int)1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int)1e9 + 23111992;
const long long LINF = (long long)1e18 + 23111992;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline unsigned long long isqrt(unsigned long long k) {
  unsigned long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline int sign(long double x, long double y) { return sign(x - y); }
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int myrand() { return abs((int)mt()); }
const int foo = (int)1e9;
namespace Maxflow {
const int maxv = 1e5 + 5;
const int maxe = 1e6 + 5;
int n, s, t, E;
int adj[maxe], nxt[maxe], lst[maxv], ptr[maxv], lev[maxv], que[maxv];
int flw[maxe], cap[maxe];
void init(int nn, int ss, int tt) {
  n = nn, s = ss, t = tt, E = 0;
  fill_n(lst, n, -1);
}
void add(int u, int v, int c1, int c2) {
  adj[E] = v, flw[E] = 0, cap[E] = c1, nxt[E] = lst[u], lst[u] = E++;
  adj[E] = u, flw[E] = 0, cap[E] = c2, nxt[E] = lst[v], lst[v] = E++;
}
int bfs() {
  fill_n(lev, n, 0), lev[s] = 1;
  int qsize = 0;
  que[qsize++] = s;
  for (int i = 0; i < qsize; i++) {
    for (int u = que[i], e = lst[u]; ~e; e = nxt[e]) {
      int v = adj[e];
      if (flw[e] < cap[e] && !lev[v]) {
        lev[v] = lev[u] + 1;
        que[qsize++] = v;
      }
    }
  }
  return lev[t];
}
int dfs(int u, int bot) {
  if (u == t) return bot;
  for (int& e = ptr[u]; ~e; e = nxt[e]) {
    int v = adj[e];
    int delta = 0;
    if (lev[v] == lev[u] + 1 && flw[e] < cap[e] &&
        (delta = dfs(v, min(bot, cap[e] - flw[e]))) > 0) {
      flw[e] += delta;
      flw[e ^ 1] -= delta;
      return delta;
    }
  }
  return 0;
}
int maxflow(int ss = -1, int tt = -1) {
  if (~ss) s = ss;
  if (~tt) t = tt;
  fill_n(flw, E, 0);
  int total = 0;
  while (bfs()) {
    for (int i = 0; i < n; i++) ptr[i] = lst[i];
    for (int delta = dfs(s, foo); delta > 0; delta = dfs(s, foo))
      total += delta;
  }
  return total;
}
vector<pair<pair<int, int>, int> > gomory_hu() {
  vector<pair<pair<int, int>, int> > tree;
  vector<int> p(n);
  for (int u = 1; u < n; u++) {
    tree.push_back(make_pair(make_pair(p[u], u), maxflow(u, p[u])));
    for (int v = u + 1; v < n; ++v) {
      if (lev[v] && p[v] == p[u]) {
        p[v] = u;
      }
    }
  }
  return tree;
}
int dfs2(int u, int pu) {
  if (u == t) {
    return pu;
  }
  for (int e = lst[u]; ~e; e = nxt[e])
    if (flw[e] > 0) {
      int v = adj[e];
      int r = dfs2(v, u);
      if (r) {
        flw[e]--;
        return r;
      }
    }
  return 0;
}
vector<pair<int, int> > trace() {
  vector<pair<int, int> > res;
  for (int e = lst[s]; ~e; e = nxt[e])
    if (flw[e] > 0) {
      int v = adj[e];
      int r;
      while (flw[e] && (r = dfs2(v, s))) {
        flw[e]--;
        res.push_back(make_pair(v, r));
      }
    }
  return res;
}
}  // namespace Maxflow
int n, m;
void build(int p, int L, int R) {
  if (L == R) {
    Maxflow::add(n + m + p, n + L, 1, 0);
    return;
  }
  build(p << 1, L, L + R >> 1);
  build(p << 1 | 1, (L + R >> 1) + 1, R);
  Maxflow::add(n + m + p, n + m + (p << 1), R - L + 1, 0);
  Maxflow::add(n + m + p, n + m + (p << 1 | 1), R - L + 1, 0);
}
void add(int id, int p, int l, int r, int L, int R) {
  if (r < L || R < l) return;
  if (l <= L && R <= r) {
    Maxflow::add(id, n + m + p, 1, 0);
    return;
  }
  add(id, p << 1, l, r, L, L + R >> 1);
  add(id, p << 1 | 1, l, r, (L + R >> 1) + 1, R);
}
void chemthan() {
  cin >> n >> m;
  int tot = n + m + 65000, s = tot++, t = tot++;
  Maxflow::init(tot, s, t);
  build(1, 0, m - 1);
  static int tp[5005];
  static vector<int> g[5005];
  for (int i = (0); i < (n); ++i) {
    int t;
    cin >> t;
    tp[i] = t;
    if (t == 0) {
      Maxflow::add(s, i, 1, 0);
      int k;
      cin >> k;
      while (k--) {
        int u;
        cin >> u;
        u--;
        Maxflow::add(i, n + u, 1, 0);
      }
    } else if (t == 1) {
      Maxflow::add(s, i, 1, 0);
      int l, r;
      cin >> l >> r;
      l--, r--;
      add(i, 1, l, r, 0, m - 1);
    } else if (t == 2) {
      Maxflow::add(s, i, 2, 0);
      int a, b, c;
      cin >> a >> b >> c;
      a--, b--, c--;
      Maxflow::add(i, n + a, 1, 0);
      Maxflow::add(i, n + b, 1, 0);
      Maxflow::add(i, n + c, 1, 0);
      g[i].push_back(a);
      g[i].push_back(b);
      g[i].push_back(c);
    }
  }
  for (int i = (0); i < (m); ++i) Maxflow::add(n + i, t, 1, 0);
  cout << Maxflow::maxflow() << "\n";
  static int to[5005];
  static int from[5005];
  static int z[5005][5005];
  vector<pair<int, int> > res = Maxflow::trace();
  for (pair<int, int> e : res) {
    z[e.first][e.second - n] = 1;
  }
  memset(to, -1, sizeof(to)), memset(from, -1, sizeof(from));
  for (int i = (0); i < (n); ++i) {
    if (tp[i] == 2) {
      vector<int> vals;
      map<int, int> used;
      for (int j = (0); j < (m); ++j) {
        if (z[i][j] > 0) {
          vals.push_back(j);
          used[j] = 1;
        }
      }
      if (int((vals).size()) && int((vals).size()) < 2) {
        for (int u : g[i]) {
          if (!used[u]) {
            from[u] = 0;
            vals.push_back(u);
            break;
          }
        }
      }
      for (int u : vals) {
        cout << i + 1 << " " << u + 1 << "\n";
      }
    }
  }
  for (int i = (0); i < (n); ++i) {
    if (tp[i] != 2) {
      for (int j = (0); j < (m); ++j) {
        if (z[i][j] > 0) {
          if (from[j] == -1) {
            cout << i + 1 << " " << j + 1 << "\n";
          }
        }
      }
    }
  }
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0), cin.tie(0);
  if (argc > 1) {
    assert(freopen(argv[1], "r", stdin));
  }
  if (argc > 2) {
    assert(freopen(argv[2], "wb", stdout));
  }
  chemthan();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}