#include <bits/stdc++.h>
using namespace std;
int i, N, Ans, j, k, Num, L;
int A[100005], Q[100005], f[100005];
struct node {
  int len, pos;
  int P[6], p[6];
} res[500005];
int cmp(const node &i, const node &j) {
  if (i.len == j.len) return i.pos < j.pos;
  return i.len > j.len;
}
int main() {
  scanf("%d", &N);
  for (i = 1; i <= N; ++i) scanf("%d", &A[i]);
  for (i = 1; i <= N; ++i)
    if (!f[i]) {
      Num = 0;
      f[i] = 1, Q[++Num] = i;
      for (k = A[i]; k != i; k = A[k]) f[k] = 1, Q[++Num] = k;
      L = 5;
      for (j = 2; j <= Num; ++j) {
        if (L == 5) {
          res[++Ans].len = L = 1;
          res[Ans].pos = Ans;
          res[Ans].P[L] = i;
        }
        ++res[Ans].len;
        res[Ans].P[++L] = Q[j];
      }
    }
  sort(res + 1, res + Ans + 1, cmp);
  for (i = 1; i <= Ans; ++i) {
    for (j = 1; j < res[i].len; ++j) res[i].p[j] = res[i].P[j + 1];
    res[i].p[res[i].len] = res[i].P[1];
  }
  for (i = 1; i < Ans; ++i) {
    for (; i < Ans && res[i].len + res[Ans].len < 6;) {
      for (j = 1; j <= res[Ans].len; ++j) {
        res[i].P[res[i].len + j] = res[Ans].P[j];
        res[i].p[res[i].len + j] = res[Ans].p[j];
      }
      res[i].len += res[Ans].len, --Ans;
    }
    if (i < Ans && res[i].len == 3) {
      res[i].len = 5, res[Ans].len = 2;
      res[i].P[4] = res[Ans].P[1];
      res[i].P[5] = res[Ans].P[2];
      res[i].p[4] = res[Ans].P[2];
      res[i].p[5] = res[Ans].P[1];
      res[Ans].p[1] = res[Ans].P[2] = res[Ans].P[3];
      res[Ans].p[2] = res[Ans].P[1];
    }
  }
  printf("%d\n", Ans);
  for (i = 1; i <= Ans; ++i) {
    printf("%d\n", res[i].len);
    for (j = 1; j < res[i].len; ++j) printf("%d ", res[i].P[j]);
    printf("%d\n", res[i].P[res[i].len]);
    for (j = 1; j < res[i].len; ++j) printf("%d ", res[i].p[j]);
    printf("%d\n", res[i].p[res[i].len]);
  }
  return 0;
}
