#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAXN = 310;
ll t;
ll n, m, k;
namespace T1 {
bool vis[MAXN * 2];
bool pos[MAXN * 2];
static ll ans = 0;
void solve() {
  static ll x;
  x = 0;
  ans = 0;
  stringstream ss;
  cin >> n >> m >> k;
  for (int i = 1; i <= m; ++i) {
    cin >> x;
    if (!vis[x]) {
      ss << 1 << ' ' << (x % (n - 1) + 1) << '\n';
      ++ans;
      vis[x] = true;
      if (vis[(x + n - 2) % (2 * n - 2) + 1]) pos[x] = true;
    } else {
      if (pos[x]) {
        ss << 1 << ' ' << (x % (n - 1) + 1) << '\n';
        ++ans;
      } else {
        ss << 1 << ' ' << n << '\n'
           << 2 << ' ' << (x % (n - 1) + 1) << ' ' << n << '\n';
        ans += 2;
        vis[x] = pos[x] = false;
        pos[(x + n - 2) % (2 * n - 2) + 1] = true;
      }
    }
  }
  cout << ans << endl << ss.str() << endl;
}
void run() {
  while (t--) {
    solve();
  }
}
}  // namespace T1
namespace T2 {
#define xpos (swp ? 2 : 1)
#define ypos (swp ? 1 : 2)
void solve() {
  static ll x, y, z, w, u;
  stringstream ss;
  static ll ans, idx;
  static bool swp;
  ans = 0;
  cin >> n >> m >> k;
  swp = false;
  /*
  swp==true: x = stk2
  swp==false: x = stk1
  */
  idx = 1;
state1:
  if (idx > m) goto output;
  cin >> x;
  ++idx;
  ss << "1 " << xpos << '\n';
  ++ans;
state2:
  if (idx > m) goto output;
  cin >> y;
  ++idx;
  if (x == y) {
    ss << "1 " << xpos << '\n';
    ++ans;
    goto state1;
  }
  ss << "1 " << ypos << '\n';
  ++ans;
state3:
  if (idx > m) goto output;
  cin >> z;
  ++idx;
  if (z == y) {
    ss << "1 " << ypos << '\n';
    ++ans;
    goto state2;
  } else if (z == x) {
    ss << "1 " << xpos << '\n';
    ++ans;
    swp = !swp;
    x = y;
    goto state2;
  }
state4:
  if (idx > m) goto output;
  cin >> w;
  ++idx;
  if (w == x) {
    ss << "1 " << ypos << "\n1 " << xpos << '\n';
    ans += 2;
    swp = !swp;
    x = y;
    goto state5;
  } else if (w == y) {
    ss << "1 " << xpos << "\n1 " << ypos << '\n';
    ans += 2;
    goto state5;
  } else {
    ss << "1 1\n1 1\n";
    ans += 2;
    goto state3;
  }
state5:
  if (idx > m) goto output;
  cin >> u;
  ++idx;
  if (u == z) {
    ss << "1 " << xpos << '\n';
    ++ans;
    goto state2;
  } else if (u == x) {
    ss << "1 " << ypos << '\n' << "2 " << xpos << ' ' << ypos << '\n';
    ans += 2;
    x = z;
    goto state2;
  }
output:
  cout << ans << endl << ss.str() << endl;
}
void run() {
  while (t--) {
    solve();
  }
}
#undef xpos
#undef ypos
}  // namespace T2
namespace T3 {
ll p[31];
deque<ll> dq[3];
pair<ll, ll> stk[63];
bool dfs(ll pos, ll cur) {
  if (cur > m && dq[0].empty() && dq[1].empty() && dq[2].empty()) return true;
  if (pos >= 2 * m) return false;
  if (cur <= m) {
    for (int i = 0; i < 3; ++i) {
      if (!dq[i].empty() && dq[i].back() == p[cur]) {
        dq[i].pop_back();
        if (dfs(pos + 1, cur + 1)) {
          stk[pos] = make_pair(i + 1, -1);
          return true;
        }
        dq[i].push_back(p[cur]);
      } else {
        dq[i].push_back(p[cur]);
        if (dfs(pos + 1, cur + 1)) {
          stk[pos] = make_pair(i + 1, -1);
          return true;
        }
        dq[i].pop_back();
      }
    }
  }
  // cout << pos << ' ' << cur << endl;
  for (int i = 0; i < 3; ++i) {
    for (int j = i + 1; j < 3; ++j) {
      if (dq[i].empty() || dq[j].empty()) continue;
      if (dq[i].front() == dq[j].front()) {
        ll tmp = dq[i].front();
        dq[i].pop_front();
        dq[j].pop_front();
        if (dfs(pos + 1, cur)) {
          stk[pos] = make_pair(i + 1, j + 1);
          return true;
        }
        dq[i].push_front(tmp);
        dq[j].push_front(tmp);
      }
    }
  }
  return false;
}
void solve() {
  cin >> n >> m >> k;
  for (int i = 1; i <= m; ++i) {
    cin >> p[i];
  }
  dfs(1, 1);
  ll idx = 1;
  stringstream ss;
  while (stk[idx].second != 0) {
    if (stk[idx].second == -1)
      ss << "1 " << stk[idx].first << '\n';
    else
      ss << "2 " << stk[idx].first << ' ' << stk[idx].second << endl;
    ++idx;
  }
  cout << idx - 1 << endl << ss.str() << endl;
}
void run() {
  while (t--) {
    solve();
  }
}
}  // namespace T3
int main() {
#ifndef DEBUG
  freopen("meow.in", "r", stdin);
  freopen("meow.out", "w", stdout);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
#endif
  cin >> t;
  if (t % 10 == 1) {
    T1::run();
  } else if (t % 10 == 2) {
    T2::run();
  } else if (t % 10 == 3) {
    T3::run();
  }
  return 0;
}