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>
#pragma GCC optimize "-O3"
using namespace std;
int a[30][30];
int n, m;
int bl[30][30];
int nd[30][30];
pair<int, int> pl[1000];
int gg[10];
vector<vector<int>> ans;
vector<vector<int>> ans2;
void add(vector<int> x) {
  ans.push_back(x);
  vector<pair<int, int>> uu;
  for (int i = 0; i < x.size(); ++i) uu.push_back(pl[x[i]]);
  for (int i = x.size() - 2; i >= 0; --i)
    swap(a[uu[i].first][uu[i].second], a[uu[i + 1].first][uu[i + 1].second]);
  for (auto p : uu) pl[a[p.first][p.second]] = p;
}
int nm(int x, int y) {
  if (x < 0 || y < 0 || x >= n || y >= m) return 0;
  if (bl[x][y]) return 0;
  return 1;
}
void mvl(int x, int y) {
  if (nm(x + 1, y) && nm(x + 1, y - 1)) {
    add({a[x][y], a[x][y - 1], a[x + 1][y - 1], a[x + 1][y]});
  } else {
    add({a[x][y], a[x][y - 1], a[x - 1][y - 1], a[x - 1][y]});
  }
}
void mvr(int x, int y) {
  if (nm(x + 1, y) && nm(x + 1, y + 1)) {
    add({a[x][y], a[x][y + 1], a[x + 1][y + 1], a[x + 1][y]});
  } else {
    add({a[x][y], a[x][y + 1], a[x - 1][y + 1], a[x - 1][y]});
  }
}
void mvd(int x, int y) {
  if (nm(x, y + 1) && nm(x + 1, y + 1)) {
    add({a[x][y], a[x + 1][y], a[x + 1][y + 1], a[x][y + 1]});
  } else {
    add({a[x][y], a[x + 1][y], a[x + 1][y - 1], a[x][y - 1]});
  }
}
void mvu(int x, int y) {
  if (nm(x, y + 1) && nm(x - 1, y + 1)) {
    add({a[x][y], a[x - 1][y], a[x - 1][y + 1], a[x][y + 1]});
  } else {
    add({a[x][y], a[x - 1][y], a[x - 1][y - 1], a[x][y - 1]});
  }
}
void combo(int a1, int a2, int a3, int a4, int a5, int a6) {
  add({a1, a2, a5, a4});
  add({a1, a4, a5, a2, a6, a3});
  add({a5, a3, a6, a2});
}
unsigned long long geths(const vector<int> &vv) {
  unsigned long long hs = 0;
  for (int i = 0; i < vv.size(); ++i) hs = hs * 10 + vv[i];
  return hs;
}
vector<int> get(vector<int> vv, int a, int b, int c, int d) {
  swap(vv[a], vv[b]);
  swap(vv[b], vv[c]);
  swap(vv[c], vv[d]);
  return vv;
}
queue<vector<int>> qu;
map<unsigned long long, pair<unsigned long long, int>> mm;
void add2(vector<int> vv, unsigned long long hs, int d) {
  unsigned long long h = geths(vv);
  if (!mm.count(h)) {
    mm[h] = {hs, d};
    qu.push(vv);
  }
}
vector<int> get2(vector<int> vv, int a, int b, int c, int d) {
  ans2.push_back({gg[vv[a]], gg[vv[b]], gg[vv[c]], gg[vv[d]]});
  swap(vv[a], vv[b]);
  swap(vv[b], vv[c]);
  swap(vv[c], vv[d]);
  return vv;
}
int main() {
  ios_base::sync_with_stdio(false), 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], --a[i][j], pl[a[i][j]] = {i, j};
  }
  int cc = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) nd[i][j] = cc++;
  }
  for (int i = n - 1; i >= 3; --i) {
    vector<int> vv;
    for (int j = 0; j < m; ++j) vv.push_back(j);
    swap(vv[m - 2], vv[m - 1]);
    for (int j : vv) {
      if (a[i][j] == nd[i][j]) {
        bl[i][j] = 1;
        continue;
      }
      while (pl[nd[i][j]].second < j)
        mvr(pl[nd[i][j]].first, pl[nd[i][j]].second);
      while (pl[nd[i][j]].second > j)
        mvl(pl[nd[i][j]].first, pl[nd[i][j]].second);
      while (pl[nd[i][j]].first < i - 1)
        mvd(pl[nd[i][j]].first, pl[nd[i][j]].second);
      if (j == vv.back()) {
        combo(a[i - 1][j - 1], a[i - 1][j], a[i - 1][j + 1], a[i][j - 1],
              a[i][j], a[i][j + 1]);
      } else {
        while (pl[nd[i][j]].first < i)
          mvd(pl[nd[i][j]].first, pl[nd[i][j]].second);
      }
      bl[i][j] = 1;
    }
  }
  for (int j = m - 1; j >= 3; --j) {
    vector<int> vv;
    for (int j = 0; j < 3; ++j) vv.push_back(j);
    swap(vv[3 - 2], vv[3 - 1]);
    for (int i : vv) {
      if (a[i][j] == nd[i][j]) {
        bl[i][j] = 1;
        continue;
      }
      while (pl[nd[i][j]].first < i)
        mvd(pl[nd[i][j]].first, pl[nd[i][j]].second);
      while (pl[nd[i][j]].first > i)
        mvu(pl[nd[i][j]].first, pl[nd[i][j]].second);
      while (pl[nd[i][j]].second < j - 1)
        mvr(pl[nd[i][j]].first, pl[nd[i][j]].second);
      if (i == vv.back()) {
        combo(a[i + 1][j - 1], a[i][j - 1], a[i - 1][j - 1], a[i + 1][j],
              a[i][j], a[i - 1][j]);
      } else {
        while (pl[nd[i][j]].second < j)
          mvr(pl[nd[i][j]].first, pl[nd[i][j]].second);
      }
      bl[i][j] = 1;
    }
  }
  vector<int> vv;
  for (int i = 0; i < 3; ++i)
    for (int j = 0; j < 3; ++j) {
      int x = a[i][j] / m;
      int y = a[i][j] % m;
      gg[x * 3 + y] = a[i][j];
      vv.push_back(x * 3 + y);
    }
  vector<int> start = vv;
  vector<int> want;
  for (int i = 0; i < 9; ++i) want.push_back(i);
  mm[geths(vv)] = {0, -1};
  qu.push(vv);
  while (true) {
    vector<int> vv = qu.front();
    qu.pop();
    unsigned long long hs = geths(vv);
    if (vv == want) {
      while (vv != start) {
        int d = mm[geths(vv)].second;
        if (d == 0) vv = get2(vv, 3, 4, 1, 0);
        if (d == 1) vv = get2(vv, 4, 5, 2, 1);
        if (d == 2) vv = get2(vv, 6, 7, 4, 3);
        if (d == 3) vv = get2(vv, 7, 8, 5, 4);
      }
      reverse(ans2.begin(), ans2.end());
      for (auto x : ans2) ans.push_back(x);
      cout << ans.size() << "\n";
      for (auto x : ans) {
        cout << x.size() << " ";
        for (int i : x) cout << i + 1 << " ";
        cout << "\n";
      }
      return 0;
    }
    vector<int> vv2 = get(vv, 0, 1, 4, 3);
    add2(vv2, hs, 0);
    vv2 = get(vv, 1, 2, 5, 4);
    add2(vv2, hs, 1);
    vv2 = get(vv, 3, 4, 7, 6);
    add2(vv2, hs, 2);
    vv2 = get(vv, 4, 5, 8, 7);
    add2(vv2, hs, 3);
  }
  return 0;
}