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 INF = 0x3f3f3f3f;
const int N = 5010;
int _w;
int n, m;
namespace Dinic {
const int V = 20000;
const int E = 2000000;
struct Edge {
  int u, v, c, f;
  Edge() {}
  Edge(int u, int v, int c, int f) : u(u), v(v), c(c), f(f) {}
};
int n, m, s, t;
int head[V], nxt[E * 2];
Edge edge[E * 2];
void init(int _n) {
  n = _n, m = 0;
  memset(head, -1, sizeof head);
}
int link(int u, int v, int c) {
  int rtn = m;
  edge[m] = Edge(u, v, c, 0);
  nxt[m] = head[u], head[u] = m++;
  edge[m] = Edge(v, u, 0, 0);
  nxt[m] = head[v], head[v] = m++;
  return rtn;
}
int dis[V], cur[V], q[V], begin, end;
bool bfs() {
  for (int i = 0; i < n; ++i) dis[i] = INF;
  dis[s] = 0, begin = end = 0;
  q[end++] = s;
  while (begin != end) {
    int u = q[begin++];
    for (int i = head[u]; ~i; i = nxt[i]) {
      Edge &e = edge[i];
      if (e.c > e.f && dis[e.v] == INF) {
        dis[e.v] = dis[u] + 1;
        q[end++] = e.v;
      }
    }
  }
  return dis[t] != INF;
}
int dfs(int u, int res) {
  if (u == t || !res) return res;
  int flow = 0;
  for (int &i = cur[u]; ~i; i = nxt[i]) {
    Edge &e = edge[i];
    if (e.c > e.f && dis[e.v] == dis[u] + 1) {
      int f = dfs(e.v, min(e.c - e.f, res));
      flow += f, res -= f;
      e.f += f, edge[i ^ 1].f -= f;
      if (!res) break;
    }
  }
  return flow;
}
int solve(int _s, int _t) {
  s = _s, t = _t;
  int flow = 0;
  while (bfs()) {
    for (int i = 0; i < n; ++i) cur[i] = head[i];
    flow += dfs(s, INF);
  }
  return flow;
}
void clear_flow() {
  for (int i = 0; i < m; ++i) edge[i].f = 0;
}
}  // namespace Dinic
int nid, s, t, id[N];
namespace SGT {
int id[N * 4], ql, qr, qv, mid[N], eid[N];
void _init(int o, int L, int R) {
  id[o] = nid++;
  if (L == R) {
    mid[L] = id[o];
    return;
  }
  int M = (L + R) / 2, lc = o << 1, rc = lc | 1;
  _init(lc, L, M), _init(rc, M + 1, R);
}
void init() { _init(1, 1, m); }
void _build(int o, int L, int R) {
  if (L == R) {
    eid[L] = Dinic::link(id[o], t, 1);
  } else {
    int M = (L + R) / 2, lc = o << 1, rc = lc | 1;
    Dinic::link(id[o], id[lc], INF);
    Dinic::link(id[o], id[rc], INF);
    _build(lc, L, M), _build(rc, M + 1, R);
  }
}
void build() { _build(1, 1, m); }
void _connect(int o, int L, int R) {
  if (L >= ql && R <= qr) {
    Dinic::link(qv, id[o], INF);
  } else {
    int M = (L + R) / 2, lc = o << 1, rc = lc | 1;
    if (ql <= M) _connect(lc, L, M);
    if (qr > M) _connect(rc, M + 1, R);
  }
}
void connect(int u, int l, int r) {
  ql = l, qr = r, qv = u;
  _connect(1, 1, m);
}
}  // namespace SGT
int type[N], l[N], r[N], a[N], b[N], c[N], ea[N], eb[N], ec[N], anscnt;
vector<pair<int, int> > con[N], ans;
set<int> beat;
void prelude() {
  using Dinic::edge;
  using SGT::eid;
  for (int i = 1; i <= m; ++i) {
    int e = eid[i];
    if (edge[e].f) beat.insert(i);
  }
}
void solve2() {
  using Dinic::edge;
  using SGT::eid;
  for (int i = 1; i <= n; ++i)
    if (type[i] == 2) {
      int cnt = 0;
      if (edge[ea[i]].f) {
        ++cnt;
        beat.erase(a[i]);
        ans.push_back(pair<int, int>(i, a[i]));
      }
      if (edge[eb[i]].f) {
        ++cnt;
        beat.erase(b[i]);
        ans.push_back(pair<int, int>(i, b[i]));
      }
      if (edge[ec[i]].f) {
        ++cnt;
        beat.erase(c[i]);
        ans.push_back(pair<int, int>(i, c[i]));
      }
      if (cnt == 1 && beat.count(a[i])) {
        ++cnt;
        beat.erase(a[i]);
        ans.push_back(pair<int, int>(i, a[i]));
      }
      if (cnt == 1 && beat.count(b[i])) {
        ++cnt;
        beat.erase(b[i]);
        ans.push_back(pair<int, int>(i, b[i]));
      }
      if (cnt == 1 && beat.count(c[i])) {
        ++cnt;
        beat.erase(c[i]);
        ans.push_back(pair<int, int>(i, c[i]));
      }
    }
}
void solve0() {
  using Dinic::edge;
  for (int i = 1; i <= n; ++i)
    if (type[i] == 0) {
      int k = (int)con[i].size();
      for (int j = 0; j < k; ++j) {
        int nod = con[i][j].first;
        int eid = con[i][j].second;
        if (edge[eid].f && beat.count(nod)) {
          beat.erase(nod);
          ans.push_back(pair<int, int>(i, nod));
        }
      }
    }
}
struct Segment {
  int u, l, r;
  Segment() {}
  Segment(int u, int l, int r) : u(u), l(l), r(r) {}
  bool operator<(const Segment &rhs) const {
    if (l == rhs.l)
      return r < rhs.r;
    else
      return l < rhs.l;
  }
};
Segment seg[N];
int segn, vis[N];
void solve1() {
  for (int i = 1; i <= n; ++i)
    if (type[i] == 1) seg[segn++] = Segment(i, l[i], r[i]);
  while (!beat.empty()) {
    int v = *beat.begin();
    beat.erase(v);
    int minr = INF;
    for (int i = 0; i < segn; ++i) {
      if (vis[i]) continue;
      int l = seg[i].l;
      int r = seg[i].r;
      if (l <= v && v <= r) minr = min(minr, r);
    }
    for (int i = 0; i < segn; ++i) {
      if (vis[i]) continue;
      int u = seg[i].u;
      int l = seg[i].l;
      int r = seg[i].r;
      if (l <= v && v <= r && r == minr) {
        vis[i] = 1;
        ans.push_back(pair<int, int>(u, v));
        break;
      }
    }
  }
}
void solve() {
  prelude();
  solve2();
  solve0();
  solve1();
  int cnt = (int)ans.size();
  assert(cnt == anscnt);
  printf("%d\n", cnt);
  for (int i = 0; i < cnt; ++i) printf("%d %d\n", ans[i].first, ans[i].second);
}
int main() {
  _w = scanf("%d%d", &n, &m);
  SGT::init();
  for (int i = 1; i <= n; ++i) id[i] = nid++;
  s = nid++, t = nid++;
  Dinic::init(nid);
  SGT::build();
  for (int i = 1; i <= n; ++i) {
    _w = scanf("%d", &type[i]);
    if (type[i] == 0) {
      Dinic::link(s, id[i], 1);
      int k;
      _w = scanf("%d", &k);
      for (int j = 0; j < k; ++j) {
        int tmp, eid;
        _w = scanf("%d", &tmp);
        eid = Dinic::link(id[i], SGT::mid[tmp], 1);
        con[i].push_back(pair<int, int>(tmp, eid));
      }
    } else if (type[i] == 1) {
      Dinic::link(s, id[i], 1);
      _w = scanf("%d%d", l + i, r + i);
      SGT::connect(id[i], l[i], r[i]);
    } else {
      Dinic::link(s, id[i], 2);
      _w = scanf("%d%d%d", a + i, b + i, c + i);
      ea[i] = Dinic::link(id[i], SGT::mid[a[i]], 1);
      eb[i] = Dinic::link(id[i], SGT::mid[b[i]], 1);
      ec[i] = Dinic::link(id[i], SGT::mid[c[i]], 1);
    }
  }
  anscnt = Dinic::solve(s, t);
  solve();
  return 0;
}