#include <bits/stdc++.h>
using namespace std;
struct elem {
  int k;
  vector<int> a;
  vector<int> b;
  elem() { k = 0; }
  elem(int ink) {
    k = ink;
    a = vector<int>(k);
    b = vector<int>(k);
  }
};
int main() {
  int n;
  cin >> n;
  vector<int> v(n + 1);
  vector<elem> sol;
  for (int i = 1; i <= n; i++) cin >> v[i];
  vector<int> indice2, indice3;
  for (int i = 1; i <= n; i++) {
    if (v[i] != i) {
      int i1 = i;
      int i2 = v[i1];
      int i3 = v[i2];
      int i4 = v[i3];
      int i5 = v[i4];
      if (i3 == i) {
        if (i2 > i) indice2.push_back(i);
      } else if (i4 == i) {
        if (i2 > i and i3 > i) indice3.push_back(i);
      } else {
        if (i5 == i) {
          elem e(4);
          e.a[0] = i1;
          e.b[0] = i2;
          swap(v[i1], v[i2]);
          e.a[1] = i2;
          e.b[1] = i3;
          swap(v[i1], v[i3]);
          e.a[2] = i3;
          e.b[2] = i4;
          swap(v[i1], v[i4]);
          e.a[3] = i4;
          e.b[3] = i1;
          sol.push_back(e);
        } else {
          elem e(5);
          e.a[0] = i1;
          e.b[0] = i2;
          swap(v[i1], v[i2]);
          e.a[1] = i2;
          e.b[1] = i3;
          swap(v[i1], v[i3]);
          e.a[2] = i3;
          e.b[2] = i4;
          swap(v[i1], v[i4]);
          e.a[3] = i4;
          e.b[3] = i5;
          swap(v[i1], v[i5]);
          e.a[4] = i5;
          e.b[4] = i1;
          sol.push_back(e);
        }
        if (v[i] != i) i--;
      }
    }
  }
  int ind2 = 0;
  int ind3 = 0;
  while (ind2 < int(indice2.size()) or ind3 < int(indice3.size())) {
    for (; ind2 < int(indice2.size()) and ind3 < int(indice3.size());
         ind2++, ind3++) {
      int i1 = indice2[ind2];
      int j1 = indice3[ind3];
      int i2 = v[i1];
      int j2 = v[j1];
      int j3 = v[j2];
      elem e(5);
      e.a[0] = i1;
      e.b[0] = i2;
      e.a[1] = i2;
      e.b[1] = i1;
      e.a[2] = j1;
      e.b[2] = j2;
      e.a[3] = j2;
      e.b[3] = j3;
      e.a[4] = j3;
      e.b[4] = j1;
      sol.push_back(e);
    }
    for (; ind2 < int(indice2.size()); ind2++) {
      if (ind2 + 1 < int(indice2.size())) {
        int i1 = indice2[ind2];
        int j1 = indice2[ind2 + 1];
        ind2++;
        int i2 = v[i1];
        int j2 = v[j1];
        elem e(4);
        e.a[0] = i1;
        e.b[0] = i2;
        e.a[1] = i2;
        e.b[1] = i1;
        e.a[2] = j1;
        e.b[2] = j2;
        e.a[3] = j2;
        e.b[3] = j1;
        sol.push_back(e);
      } else {
        int i1 = indice2[ind2];
        int i2 = v[i1];
        elem e(2);
        e.a[0] = i1;
        e.b[0] = i2;
        e.a[1] = i2;
        e.b[1] = i1;
        sol.push_back(e);
      }
    }
    bool trencament = false;
    for (; ind3 < int(indice3.size()) and not trencament; ind3++) {
      if (ind3 + 1 < int(indice3.size())) {
        int i1 = indice3[ind3];
        int i2 = v[i1];
        int i3 = v[i2];
        elem e(5);
        e.a[0] = i1;
        e.b[0] = i2;
        e.a[1] = i2;
        e.b[1] = i3;
        e.a[2] = i3;
        e.b[2] = i1;
        int j1 = indice3[ind3 + 1];
        int j2 = v[j1];
        int j3 = v[j2];
        ind3++;
        e.a[3] = j2;
        e.b[3] = j3;
        e.a[4] = j3;
        e.b[4] = j2;
        swap(v[j2], v[j3]);
        sol.push_back(e);
        indice2.push_back(j1);
        trencament = true;
      } else {
        int i1 = indice3[ind3];
        int i2 = v[i1];
        int i3 = v[i2];
        elem e(3);
        e.a[0] = i1;
        e.b[0] = i2;
        e.a[1] = i2;
        e.b[1] = i3;
        e.a[2] = i3;
        e.b[2] = i1;
        sol.push_back(e);
      }
    }
  }
  cout << int(sol.size()) << endl;
  for (int i = 0; i < int(sol.size()); i++) {
    elem e = sol[i];
    cout << e.k << endl;
    for (int j = 0; j < e.k; j++) {
      if (j > 0) cout << " ";
      cout << e.a[j];
    }
    cout << endl;
    for (int j = 0; j < e.k; j++) {
      if (j > 0) cout << " ";
      cout << e.b[j];
    }
    cout << endl;
  }
}
