#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
const long long oo = 1e18;
const long long mod = 1e9 + 7;
int g[4][51];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool vis[4][51];
int n, k;
vector<pair<int, pair<int, int>>> ans;
void dfs(int r, int c) {
  if (vis[r][c]) return;
  vis[r][c] = 1;
  if (r == 2) {
    if (!c && !vis[1][c]) {
      g[r][c] = g[1][c];
      g[1][c] = 0;
      if (g[r][c]) ans.push_back({g[r][c], {r, c}});
    } else if (!vis[r][c - 1]) {
      g[r][c] = g[r][c - 1];
      g[r][c - 1] = 0;
      if (g[r][c]) ans.push_back({g[r][c], {r, c}});
    }
    if (!c)
      dfs(1, c);
    else
      dfs(r, c - 1);
  } else {
    if (c < n - 1 && !vis[r][c + 1]) {
      g[r][c] = g[r][c + 1];
      g[r][c + 1] = 0;
      if (g[r][c]) ans.push_back({g[r][c], {r, c}});
    } else if (!vis[r + 1][c]) {
      g[r][c] = g[r + 1][c];
      g[r + 1][c] = 0;
      if (g[r][c]) ans.push_back({g[r][c], {r, c}});
    }
    if (c == n - 1)
      dfs(2, c);
    else
      dfs(r, c + 1);
  }
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < n; j++) cin >> g[i][j];
  while (1) {
    for (int i = 1; i < 3; i++)
      for (int j = 0; j < n; j++)
        if (g[i][j]) {
          for (int x = 0; x < 4; x++) {
            int nx = i + dx[x];
            int ny = j + dy[x];
            if (ny < 0 || ny == n) continue;
            if (g[nx][ny] == g[i][j]) {
              ans.push_back({g[i][j], {nx, ny}});
              g[i][j] = 0;
              break;
            }
          }
        }
    int cnt = 0;
    int sx, sy;
    for (int i = 1; i < 3; i++)
      for (int j = 0; j < n; j++) {
        cnt += (g[i][j] > 0);
        vis[i][j] = 0;
        if (!g[i][j]) {
          sy = j;
          sx = i;
        }
      }
    if (cnt == 2 * n) {
      puts("-1");
      return 0;
    } else if (!cnt) {
      break;
    }
    dfs(sx, sy);
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << ' ' << ans[i].second.first + 1 << ' '
         << ans[i].second.second + 1 << endl;
}
