#include <bits/stdc++.h>
int N, S, a[100005], e[100005], qs[100005], s[7], c[7][100005][7], o[7],
    q[100005][7][2];
bool b[100005];
void print(int p, int x) {
  o[x + 1] = o[1];
  for (int i = 1; i <= x; i++)
    q[p][++qs[p]][0] = o[i], q[p][qs[p]][1] = o[i + 1];
}
void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d", &a[i]);
  for (int i = 1, j, k, l; i <= N; i++)
    if (!b[i]) {
      l = 0;
      for (int x = i; !b[x]; b[x] = 1, x = a[x]) e[++l] = x;
      if (l >= 5) {
        for (j = 1, k = 1; j + 4 <= l; j += 4)
          o[1] = e[1], o[2] = e[j + 1], o[3] = e[j + 2], o[4] = e[j + 3],
          o[5] = e[j + 4], print(++S, 5);
        for (; j < l; e[++k] = e[++j])
          ;
        if (!(l %= 4)) l = 4;
      }
      memcpy(c[l][++s[l]], e, sizeof(o));
    }
}
void doit() {
  for (; s[4];) memcpy(o, c[4][s[4]--], sizeof(o)), print(++S, 4);
bg:
  for (; s[2] && s[3];)
    memcpy(o, c[2][s[2]--], sizeof(o)), print(++S, 2),
        memcpy(o, c[3][s[3]--], sizeof(o)), print(S, 3);
  if (s[3] >= 2) {
    memcpy(o, c[3][s[3]--], sizeof(o)), print(++S, 3);
    o[1] = c[3][s[3]][1], o[2] = c[3][s[3]][2], print(S, 2),
    c[2][++s[2]][1] = o[1], c[2][s[2]][2] = c[3][s[3]--][3];
    goto bg;
  }
  if (s[3]) memcpy(o, c[3][s[3]--], sizeof(o)), print(++S, 3);
  for (; s[2];) {
    memcpy(o, c[2][s[2]--], sizeof(o)), print(++S, 2);
    if (s[2]) memcpy(o, c[2][s[2]--], sizeof(o)), print(S, 2);
  }
  printf("%d\n", S);
  for (int i = 1; i <= S; i++) {
    printf("%d\n", qs[i]);
    for (int k = 0; k < 2; k++)
      for (int j = 1; j <= qs[i]; j++)
        printf("%d%c", q[i][j][k], j == qs[i] ? '\n' : ' ');
  }
}
int main() {
  init();
  doit();
}
