#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int a[MAXN];
int b[MAXN];
bool vis[MAXN];
vector<pair<int, int> > x[MAXN];
vector<int> v[6];
vector<int> ans[MAXN];
int main() {
  int n, i, j, k;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  int tot = 0;
  for (i = 1; i <= n; i++) {
    if (vis[i] == 0 && a[i] != i) {
      int t = i, num = 0;
      while (vis[t] == 0) {
        vis[t] = 1;
        x[tot].push_back(make_pair(t, b[t]));
        num++;
        t = b[t];
        if (num == 5 && vis[t] == 0) {
          x[tot][4].second = i;
          b[i] = t;
          vis[i] = 0;
          i--;
          break;
        }
      }
      v[num].push_back(tot);
      tot++;
    }
  }
  int len = 0;
  for (i = 0; i < v[5].size(); i++, len++) ans[len].push_back(v[5][i]);
  for (i = 0; i < v[4].size(); i++, len++) ans[len].push_back(v[4][i]);
  int la = v[2].size();
  int lb = v[3].size();
  for (i = 0; i < la && i < lb; i++) {
    ans[len].push_back(v[2][i]);
    ans[len].push_back(v[3][i]);
    len++;
  }
  if (i < la) {
    for (j = i; j < la; j++) {
      ans[len].push_back(v[2][j]);
      j++;
      if (j < la) ans[len].push_back(v[2][j]);
      len++;
    }
  }
  if (i < lb) {
    for (j = i; j < lb;) {
      ans[len].push_back(v[3][j]);
      len++;
      j++;
      if (j < lb) {
        ans[len].push_back(v[3][j]);
        len++;
      }
      j++;
      if (j < lb) {
        x[tot].push_back(make_pair(x[v[3][j]][1].first, x[v[3][j]][1].second));
        x[tot].push_back(make_pair(x[v[3][j]][1].second, x[v[3][j]][1].first));
        ans[len - 2].push_back(tot);
        tot++;
        x[tot].push_back(make_pair(x[v[3][j]][0].first, x[v[3][j]][0].second));
        x[tot].push_back(make_pair(x[v[3][j]][0].second, x[v[3][j]][0].first));
        ans[len - 1].push_back(tot);
        tot++;
        j++;
      }
    }
  }
  printf("%d\n", len);
  for (i = 0; i < len; i++) {
    int sum = 0;
    for (j = 0; j < ans[i].size(); j++) sum += x[ans[i][j]].size();
    printf("%d\n", sum);
    for (j = 0; j < ans[i].size(); j++) {
      int t = ans[i][j];
      for (k = 0; k < x[t].size(); k++) printf("%d ", x[t][k].first);
    }
    printf("\n");
    for (j = 0; j < ans[i].size(); j++) {
      int t = ans[i][j];
      for (k = 0; k < x[t].size(); k++) printf("%d ", x[t][k].second);
    }
    printf("\n");
  }
  return 0;
}
