Problem: You are given an n × m grid. Each grid cell is filled with a unique integer from 1 to nm so that each integer appears exactly once.

In one operation, you can choose an arbitrary cycle of the grid and move all integers along that cycle one space over. Here, a cycle is any sequence that satisfies the following conditions:

  * There are at least four squares. 
  * Each square appears at most once. 
  * Every pair of adjacent squares, and also the first and last squares, share an edge. 



For example, if we had the following grid:

<image>

We can choose an arbitrary cycle like this one:

<image>

To get the following grid:

<image>

In this particular case, the chosen cycle can be represented as the sequence [1, 2, 3, 6, 5, 8, 7, 4], the numbers are in the direction that we want to rotate them in.

Find any sequence of operations to sort the grid so that the array created by concatenating the rows from the highest to the lowest is sorted (look at the first picture above).

Note you do not need to minimize number of operations or sum of cycle lengths. The only constraint is that the sum of all cycles lengths must not be greater than 10^5. We can show that an answer always exists under the given constraints. Output any valid sequence of moves that will sort the grid.

Input

The first line contains two integers n and m (3 ≤ n,m ≤ 20) — the dimensions of the grid.

Each of the next n lines contains m integers x_{i,1}, x_{i,2}, …, x_{i, m} (1 ≤ x_{i,j} ≤ nm), denoting the values of the block in row i and column j. 

It is guaranteed that all x_{i,j} are distinct.

Output

First, print a single integer k, the number of operations (k ≥ 0).

On each of the next k lines, print a cycle as follows:

$$$s\ y_1\ y_2\ …\ y_s$$$

Here, s is the number of blocks to move (s ≥ 4). Here we have block y_1 moving to where block y_2 is, block y_2 moving to where block y_3 is, and so on with block y_s moving to where block y_1 is.

The sum of s over all operations must be at most 10^5.

Examples

Input

3 3
4 1 2
7 6 3
8 5 9


Output

1
8 1 4 7 8 5 6 3 2

Input

3 5
1 2 3 5 10
11 6 4 14 9
12 7 8 13 15


Output

3
4 4 14 13 8
4 5 10 9 4
4 12 7 6 11

Note

The first sample is the case in the statement. Here, we can use the cycle in reverse order to sort the grid.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 998244353;
ll binpow(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1) res = (res * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
ll modInv(ll a) { return binpow(a, MOD - 2); }
const int INF = 0x3f3f3f3f;
const int mxN = 21;
int n, m;
int arr[mxN][mxN];
pair<int, int> rpos[mxN * mxN];
vector<vector<int>> res;
void query(vector<pair<int, int>> a) {
  res.push_back({});
  res.back().push_back((int)a.size());
  for (auto k : a) {
    res.back().push_back(arr[k.first][k.second]);
  }
  for (int i = ((int)a.size() - 1) - 1; i >= (0); --i) {
    if (a[i].first != a[i + 1].first && a[i].second != a[i + 1].second) {
      cout << "RIP\n";
      exit(0);
    }
    swap(arr[a[i].first][a[i].second], arr[a[i + 1].first][a[i + 1].second]);
  }
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (m); ++j) {
      rpos[arr[i][j]] = {i, j};
    }
  }
}
void vswap(pair<int, int> b) {
  if (b.second == m - 1) {
    vector<pair<int, int>> q;
    q.push_back({b.first, b.second});
    q.push_back({b.first - 1, b.second});
    q.push_back({b.first - 1, b.second - 1});
    q.push_back({b.first, b.second - 1});
    query(q);
    q.clear();
    b.first--;
    q.push_back({b.first, b.second});
    q.push_back({b.first - 1, b.second});
    q.push_back({b.first - 1, b.second - 1});
    q.push_back({b.first, b.second - 1});
    query(q);
    q.clear();
    q.push_back({b.first, b.second});
    q.push_back({b.first + 1, b.second});
    q.push_back({b.first + 1, b.second - 1});
    q.push_back({b.first, b.second - 1});
    q.push_back({b.first - 1, b.second - 1});
    q.push_back({b.first - 1, b.second});
    query(q);
  } else {
    vector<pair<int, int>> q;
    q.push_back({b.first, b.second});
    q.push_back({b.first - 1, b.second});
    q.push_back({b.first - 1, b.second + 1});
    q.push_back({b.first, b.second + 1});
    query(q);
    q.clear();
    b.first--;
    q.push_back({b.first, b.second});
    q.push_back({b.first - 1, b.second});
    q.push_back({b.first - 1, b.second + 1});
    q.push_back({b.first, b.second + 1});
    query(q);
    q.clear();
    q.push_back({b.first, b.second});
    q.push_back({b.first + 1, b.second});
    q.push_back({b.first + 1, b.second + 1});
    q.push_back({b.first, b.second + 1});
    q.push_back({b.first - 1, b.second + 1});
    q.push_back({b.first - 1, b.second});
    query(q);
  }
}
void hswap(pair<int, int> b) {
  if (b.second == m - 1) {
    vector<pair<int, int>> q;
    q.push_back({b.first, b.second});
    q.push_back({b.first, b.second - 1});
    q.push_back({b.first - 1, b.second - 1});
    q.push_back({b.first - 1, b.second});
    query(q);
    q.clear();
    b.second--;
    q.push_back({b.first, b.second});
    q.push_back({b.first, b.second - 1});
    q.push_back({b.first - 1, b.second - 1});
    q.push_back({b.first - 1, b.second});
    query(q);
    q.clear();
    q.push_back({b.first, b.second});
    q.push_back({b.first, b.second + 1});
    q.push_back({b.first - 1, b.second + 1});
    q.push_back({b.first - 1, b.second});
    q.push_back({b.first - 1, b.second - 1});
    q.push_back({b.first, b.second - 1});
    query(q);
  } else {
    vector<pair<int, int>> q;
    b.second--;
    q.push_back({b.first, b.second});
    q.push_back({b.first, b.second + 1});
    q.push_back({b.first - 1, b.second + 1});
    q.push_back({b.first - 1, b.second});
    query(q);
    q.clear();
    b.second++;
    q.push_back({b.first, b.second});
    q.push_back({b.first, b.second + 1});
    q.push_back({b.first - 1, b.second + 1});
    q.push_back({b.first - 1, b.second});
    query(q);
    q.clear();
    q.push_back({b.first, b.second});
    q.push_back({b.first, b.second - 1});
    q.push_back({b.first - 1, b.second - 1});
    q.push_back({b.first - 1, b.second});
    q.push_back({b.first - 1, b.second + 1});
    q.push_back({b.first, b.second + 1});
    query(q);
  }
}
void move(pair<int, int> a, pair<int, int> b) {
  if (a.first != n - 1) {
    while (a.second < b.second) {
      vector<pair<int, int>> q;
      q.push_back({a.first, a.second});
      q.push_back({a.first, a.second + 1});
      q.push_back({a.first + 1, a.second + 1});
      q.push_back({a.first + 1, a.second});
      query(q);
      a.second++;
    }
    while (a.second > b.second) {
      vector<pair<int, int>> q;
      q.push_back({a.first, a.second});
      q.push_back({a.first, a.second - 1});
      q.push_back({a.first + 1, a.second - 1});
      q.push_back({a.first + 1, a.second});
      query(q);
      a.second--;
    }
  } else {
    while (a.second < b.second) {
      vector<pair<int, int>> q;
      q.push_back({a.first, a.second});
      q.push_back({a.first, a.second + 1});
      q.push_back({a.first - 1, a.second + 1});
      q.push_back({a.first - 1, a.second});
      query(q);
      a.second++;
    }
    while (a.second > b.second) {
      vector<pair<int, int>> q;
      q.push_back({a.first, a.second});
      q.push_back({a.first, a.second - 1});
      q.push_back({a.first - 1, a.second - 1});
      q.push_back({a.first - 1, a.second});
      query(q);
      a.second--;
    }
  }
  while (a.first > b.first) {
    vector<pair<int, int>> q;
    q.push_back({a.first, a.second});
    q.push_back({a.first - 1, a.second});
    q.push_back({a.first - 1, a.second + 1});
    q.push_back({a.first, a.second + 1});
    query(q);
    a.first--;
  }
}
void bubblesort(int x, bool rev) {
  for (int i = (0); i < (m - 1); ++i) {
    for (int j = (0); j < (m - i - 1); ++j) {
      if (rev) {
        if (arr[x][j] < arr[x][j + 1]) {
          hswap({x, j + 1});
        }
      } else {
        if (arr[x][j] > arr[x][j + 1]) {
          hswap({x, j + 1});
        }
      }
    }
  }
}
int main() {
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> m;
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (m); ++j) {
      cin >> arr[i][j];
      rpos[arr[i][j]] = {i, j};
    }
  }
  for (int i = (0); i < (n - 2); ++i) {
    for (int j = (0); j < (m - 1); ++j) {
      int num = m * i + j + 1;
      if (j == m - 2) {
        vector<pair<int, int>> q;
        while (rpos[num].first == i) {
          q.push_back({i, m - 2});
          q.push_back({i, m - 1});
          q.push_back({i + 1, m - 1});
          q.push_back({i + 1, m - 2});
          query(q);
          q.clear();
        }
        q.push_back({i + 1, m - 2});
        q.push_back({i + 1, m - 1});
        q.push_back({i + 2, m - 1});
        q.push_back({i + 2, m - 2});
        query(q);
        num++;
      }
      move(rpos[num], {i, j});
    }
    if (rpos[m * (i + 1) - 1].first == i) continue;
    move(rpos[m * (i + 1) - 1], {i + 1, m - 2});
    vector<pair<int, int>> q;
    q.push_back({i, m - 2});
    q.push_back({i, m - 1});
    q.push_back({i + 1, m - 1});
    q.push_back({i + 1, m - 2});
    query(q);
  }
  bubblesort(n - 2, 0);
  bubblesort(n - 1, 1);
  for (int j = (0); j < (m); ++j) {
    if (arr[n - 2][j] > m * (n - 1)) {
      vswap({n - 1, j});
    }
  }
  bubblesort(n - 2, 0);
  bubblesort(n - 1, 0);
  cout << res.size() << "\n";
  for (auto p : res) {
    for (auto a : p) {
      cout << a << " ";
    }
    cout << "\n";
  }
  return 0;
}