#include <cstring>
#include <fstream>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
std::ifstream fin("meow.in");
std::ofstream fout("meow.out");
int T, n, m, k, a[2000001], st[301][3], top[301], nxt[2000001], P[1001];
bool vis[301];
struct Node {
  int op, x, y;
  Node(int op = 0, int x = 0, int y = 0) : op(op), x(x), y(y) {}
};
bool ff[2000001];
int wh[1001];
std::deque<int> Q[301];
void Solve() {
  std::cin >> n >> m >> k;
  for (int i = 1; i <= m; i++) std::cin >> a[i];
  std::vector<Node> sol;
  std::memset(st, 0, sizeof(st)), std::memset(top, 0, sizeof(top));
  std::memset(vis, 0, sizeof(vis));
  if (k == 2 * n - 2) {
    for (int i = 1; i <= m; i++) {
      int pos = a[i] % (n - 1) + 1;
      if (vis[a[i]]) {
        if (st[pos][top[pos]] == a[i]) {
          sol.emplace_back(1, pos);
          top[pos]--;
        } else {
          sol.emplace_back(1, n);
          sol.emplace_back(2, pos, n);
          st[pos][top[pos] = 1] = st[pos][2];
        }
        vis[a[i]] = false;
      } else {
        sol.emplace_back(1, pos);
        st[pos][++top[pos]] = a[i];
        vis[a[i]] = true;
      }
    }
  } else {
    for (int i = 1; i <= m; i++) ff[i] = false;
    for (int i = 1; i < m; i++)
      if (a[i] == a[i + 1]) ff[i++] = true;
    for (int i = 1; i <= m; i++)
      if (ff[i]) a[i] = a[i + 1] = 0;
    for (int i = 1; i <= k; i++) P[i] = n + 1;
    for (int i = m; i >= 1; i--) nxt[i] = P[a[i]], P[a[i]] = i;
    for (int i = 1; i <= n; i++) Q[i].clear();
    std::set<std::pair<int, int>> q;
    for (int i = 1; i <= n; i++) q.emplace(m + 1, i);
    for (int i = 1; i <= k; i++) P[i] = 0;
    for (int i = 1; i <= m; i++) {
      if (ff[i]) {
        sol.emplace_back(1, 1);
        sol.emplace_back(1, 1);
        i++;
        continue;
      }
      if (!vis[a[i]]) {
        std::pair<int, int> tmp = *q.rbegin();
        q.erase(--q.end());
        int pos = tmp.second;
        wh[a[i]] = pos;
        Q[pos].emplace_back(a[i]);
        if (Q[pos].size() == 1) q.emplace(nxt[i], pos);
        sol.emplace_back(1, pos);
        vis[a[i]] = true;
        P[a[i]] = i;
      } else {
        int pos = wh[a[i]];
        if (Q[pos].back() == a[i]) {
          sol.emplace_back(1, pos);
          Q[pos].pop_back();
          if (Q[pos].empty()) q.erase({i, pos});
          if (!Q[pos].empty()) {
            q.emplace(nxt[P[Q[pos].front()]], pos);
          }
        } else {
          int to = (*q.rbegin()).second;
          sol.emplace_back(1, to);
          sol.emplace_back(2, pos, to);
          Q[pos].pop_front();
        }
        wh[a[i]] = 0;
        vis[a[i]] = false;
      }
    }
  }
  std::cout << sol.size() << '\n';
  for (const auto &tmp : sol) {
    int op = tmp.op;
    if (op == 1)
      std::cout << op << ' ' << tmp.x << '\n';
    else
      std::cout << op << ' ' << tmp.x << ' ' << tmp.y << '\n';
  }
}
int main(int argc, char const *argv[]) {
  // freopen("meow.in", "r", stdin);
  std::cin.rdbuf(fin.rdbuf()), std::cout.rdbuf(fout.rdbuf());
  std::cin.tie(nullptr);
  std::cin >> T;
  while (T--) Solve();
  return 0;
}