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;
const int N = 22;
int n, m;
int a[N][N];
vector<vector<int>> ans;
void showState() {
  cerr << "ShowStart!" << endl;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cerr << a[i][j] << ' ';
    cerr << endl;
  }
  cerr << "ShowEnd!" << endl;
}
void rotate(int x, int y, int dir) {
  vector<int> vec;
  vector<pair<int, int>> pos;
  vec.emplace_back(a[x][y]), pos.emplace_back(x, y);
  vec.emplace_back(a[x][y + 1]), pos.emplace_back(x, y + 1);
  vec.emplace_back(a[x + 1][y + 1]), pos.emplace_back(x + 1, y + 1);
  vec.emplace_back(a[x + 1][y]), pos.emplace_back(x + 1, y);
  if (dir) reverse(vec.begin(), vec.end()), reverse(pos.begin(), pos.end());
  for (int i = 0; i < vec.size(); i++) {
    int _x = pos[i].first, _y = pos[i].second;
    a[_x][_y] = vec[(i - 1 + pos.size()) % pos.size()];
  }
  ans.push_back(vec);
}
void getPosition(int x, int &px, int &py) {
  for (int _x = 0; _x < n; _x++) {
    for (int _y = 0; _y < m; _y++) {
      if (a[_x][_y] == x) {
        px = _x, py = _y;
        return;
      }
    }
  }
}
struct state {
  int p[9];
  int hash() {
    int pw = 1, val = 0;
    for (int i = 0; i < 9; i++) {
      val += p[i] * pw;
      pw *= 9;
    }
    return val;
  }
};
unordered_map<int, int> vis;
unordered_map<int, pair<int, vector<int>>> up;
vector<vector<int>> arrays;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n - 3; i++) {
    for (int j = 0; j < m - 1; j++) {
      int x = i * m + j + 1, px, py;
      getPosition(x, px, py);
      while (py > j) {
        if (px == n - 1)
          rotate(px - 1, py - 1, 0), py--;
        else
          rotate(px, py - 1, 1), py--;
      }
      while (py < j) {
        if (px == n - 1)
          rotate(px - 1, py, 1), py++;
        else
          rotate(px, py, 0), py++;
      }
      while (px > i) {
        rotate(px - 1, py, 0), px--;
      }
    }
    int j = m - 1;
    int x = i * m + j + 1, px, py;
    getPosition(x, px, py);
    if (px == i && py == j) continue;
    while (py < j) {
      if (px == n - 1)
        rotate(px - 1, py, 1), py++;
      else
        rotate(px, py, 0), py++;
    }
    while (px > i + 2) rotate(px - 1, py - 1, 1), px--;
    while (px < i + 2) rotate(px, py - 1, 0), px++;
    rotate(i, j - 1, 0);
    rotate(i + 1, j - 1, 1);
    rotate(i, j - 1, 1);
  }
  for (int j = 0; j < m - 3; j++) {
    for (int i = n - 3; i < n - 1; i++) {
      int x = i * m + j + 1, px, py;
      getPosition(x, px, py);
      while (px > i) {
        if (py == m - 1)
          rotate(px - 1, py - 1, 1), px--;
        else
          rotate(px - 1, py, 0), px--;
      }
      while (px < i) {
        if (py == m - 1)
          rotate(px, py - 1, 0), px++;
        else
          rotate(px, py, 1), px++;
      }
      while (py > j) {
        rotate(px, py - 1, 1), py--;
      }
    }
    int i = n - 1;
    int x = i * m + j + 1, px, py;
    getPosition(x, px, py);
    if (px == i && py == j) continue;
    while (px < i) {
      if (py == m - 1)
        rotate(px, py - 1, 0), px++;
      else
        rotate(px, py, 1), px++;
    }
    while (py > j + 2) rotate(px - 1, py - 1, 0), py--;
    while (py < j + 2) rotate(px - 1, py, 1), py++;
    rotate(i - 1, j, 1);
    rotate(i - 1, j + 1, 0);
    rotate(i - 1, j, 0);
  }
  vector<int> rest;
  for (int i = n - 3; i < n; i++) {
    for (int j = m - 3; j < m; j++) {
      rest.push_back(a[i][j]);
    }
  }
  sort(rest.begin(), rest.end());
  int b[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      b[i][j] = lower_bound(rest.begin(), rest.end(), a[i + n - 3][j + m - 3]) -
                rest.begin();
    }
  }
  arrays.push_back({0, 1, 4, 3});
  arrays.push_back({1, 2, 5, 4});
  arrays.push_back({3, 4, 7, 6});
  arrays.push_back({4, 5, 8, 7});
  arrays.push_back({0, 1, 2, 5, 4, 3});
  arrays.push_back({1, 2, 5, 8, 7, 4});
  arrays.push_back({3, 4, 5, 8, 7, 6});
  arrays.push_back({0, 1, 4, 7, 6, 3});
  arrays.push_back({1, 2, 5, 8, 7, 6, 3, 4});
  arrays.push_back({0, 1, 4, 5, 8, 7, 6, 3});
  arrays.push_back({0, 1, 2, 5, 8, 7, 4, 3});
  arrays.push_back({0, 1, 2, 5, 4, 7, 6, 3});
  arrays.push_back({0, 1, 2, 5, 8, 7, 6, 3});
  for (int i = 0; i < 13; i++) {
    auto t = arrays[i];
    reverse(t.begin(), t.end());
    arrays.push_back(t);
  }
  state st, final;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) st.p[i * 3 + j] = b[i][j];
  }
  for (int i = 0; i < 9; i++) final.p[i] = i;
  int finalstate = final.hash();
  int start = st.hash();
  queue<state> que;
  vis[start] = 1;
  que.push(st);
  if (start != finalstate)
    while (!que.empty()) {
      state cur = que.front();
      int curstate = cur.hash();
      que.pop();
      int flg = 0;
      for (auto t : arrays) {
        state nw = cur;
        for (int i = t.size() - 2; i >= 0; i--) {
          swap(nw.p[t[i]], nw.p[t[(i + 1) % t.size()]]);
        }
        int nwstate = nw.hash();
        if (vis[nwstate]) continue;
        if (nwstate == finalstate) {
          flg = 1;
          vector<vector<int>> append;
          append.push_back(t);
          while (curstate != start) {
            auto tt = up[curstate];
            append.push_back(tt.second);
            curstate = tt.first;
          }
          reverse(append.begin(), append.end());
          for (auto t : append) {
            vector<int> nvec;
            for (int x : t) nvec.push_back(rest[st.p[x]]);
            for (int i = t.size() - 2; i >= 0; i--) {
              swap(st.p[t[i]], st.p[t[(i + 1) % t.size()]]);
            }
            ans.push_back(nvec);
          }
          break;
        }
        que.push(nw);
        vis[nwstate] = 1;
        up[nwstate] = make_pair(curstate, t);
      }
      if (flg) break;
    }
  cout << ans.size() << endl;
  for (auto t : ans) {
    cout << t.size();
    for (int x : t) cout << ' ' << x;
    cout << endl;
  }
}