#include <bits/stdc++.h>
int in[120000], used[120000];
int cyc2[120000][7], cyc2_size;
int cyc3[120000][7], cyc3_size;
int now[120000], now_len;
int resA[120000][7], resB[120000][7], res_len[120000], res_size;
void proc(int now[], int now_len) {
  int i, j, k;
  if (now_len == 1) return;
  if (now_len == 2) {
    for (i = 0; i < 2; i++) cyc2[cyc2_size][i] = now[i];
    cyc2_size++;
    return;
  }
  if (now_len == 3) {
    for (i = 0; i < 3; i++) cyc3[cyc3_size][i] = now[i];
    cyc3_size++;
    return;
  }
  if (now_len == 4 || now_len == 5) {
    res_len[res_size] = now_len;
    for (i = 0; i < now_len; i++) resA[res_size][i] = now[i];
    for (i = 0; i < now_len; i++) resB[res_size][i] = now[(i + 1) % now_len];
    res_size++;
    return;
  }
  res_len[res_size] = 5;
  for (i = 0; i < 5; i++) resA[res_size][i] = now[i];
  for (i = 0; i < 5; i++) resB[res_size][(i + 4) % 5] = now[i];
  now[4] = now[0];
  res_size++;
  proc(now + 4, now_len - 4);
}
int main() {
  int i, j, k, l, m, n;
  int start;
  while (scanf("%d", &n) == 1) {
    for (i = 0; i < n; i++) scanf("%d", in + i);
    for (i = 0; i < n; i++) used[i] = 0;
    for (i = 0; i < n; i++) in[i]--;
    cyc2_size = cyc3_size = res_size = 0;
    for (start = 0; start < n; start++)
      if (!used[start]) {
        now_len = 0;
        k = start;
        while (!used[k]) {
          now[now_len++] = k;
          used[k] = 1;
          k = in[k];
        }
        proc(now, now_len);
      }
    while (cyc2_size && cyc3_size) {
      res_len[res_size] = 5;
      for (i = 0; i < 2; i++) resA[res_size][i] = cyc2[cyc2_size - 1][i];
      for (i = 0; i < 2; i++)
        resB[res_size][i] = cyc2[cyc2_size - 1][(i + 1) % 2];
      for (i = 0; i < 3; i++) resA[res_size][i + 2] = cyc3[cyc3_size - 1][i];
      for (i = 0; i < 3; i++)
        resB[res_size][i + 2] = cyc3[cyc3_size - 1][(i + 1) % 3];
      res_size++;
      cyc2_size--;
      cyc3_size--;
    }
    while (cyc3_size >= 3) {
      res_len[res_size] = 5;
      for (i = 0; i < 3; i++) resA[res_size][i] = cyc3[cyc3_size - 1][i];
      for (i = 0; i < 3; i++)
        resB[res_size][i] = cyc3[cyc3_size - 1][(i + 1) % 3];
      cyc3_size--;
      res_len[res_size + 1] = 5;
      for (i = 0; i < 3; i++) resA[res_size + 1][i] = cyc3[cyc3_size - 1][i];
      for (i = 0; i < 3; i++)
        resB[res_size + 1][i] = cyc3[cyc3_size - 1][(i + 1) % 3];
      cyc3_size--;
      resA[res_size][3] = cyc3[cyc3_size - 1][0];
      resA[res_size][4] = cyc3[cyc3_size - 1][1];
      resB[res_size][3] = cyc3[cyc3_size - 1][1];
      resB[res_size][4] = cyc3[cyc3_size - 1][0];
      resA[res_size + 1][3] = cyc3[cyc3_size - 1][0];
      resA[res_size + 1][4] = cyc3[cyc3_size - 1][2];
      resB[res_size + 1][3] = cyc3[cyc3_size - 1][2];
      resB[res_size + 1][4] = cyc3[cyc3_size - 1][0];
      cyc3_size--;
      res_size += 2;
    }
    while (cyc2_size >= 2) {
      res_len[res_size] = 4;
      for (i = 0; i < 2; i++) resA[res_size][i] = cyc2[cyc2_size - 1][i];
      for (i = 0; i < 2; i++)
        resB[res_size][i] = cyc2[cyc2_size - 1][(i + 1) % 2];
      cyc2_size--;
      for (i = 0; i < 2; i++) resA[res_size][i + 2] = cyc2[cyc2_size - 1][i];
      for (i = 0; i < 2; i++)
        resB[res_size][i + 2] = cyc2[cyc2_size - 1][(i + 1) % 2];
      cyc2_size--;
      res_size++;
    }
    while (cyc2_size) {
      res_len[res_size] = 2;
      for (i = 0; i < 2; i++) resA[res_size][i] = cyc2[cyc2_size - 1][i];
      for (i = 0; i < 2; i++)
        resB[res_size][i] = cyc2[cyc2_size - 1][(i + 1) % 2];
      res_size++;
      cyc2_size--;
    }
    while (cyc3_size) {
      res_len[res_size] = 3;
      for (i = 0; i < 3; i++) resA[res_size][i] = cyc3[cyc3_size - 1][i];
      for (i = 0; i < 3; i++)
        resB[res_size][i] = cyc3[cyc3_size - 1][(i + 1) % 3];
      res_size++;
      cyc3_size--;
    }
    printf("%d\n", res_size);
    for (i = 0; i < res_size; i++) {
      printf("%d\n", res_len[i]);
      for (k = 0; k < res_len[i]; k++) {
        if (k) putchar(' ');
        printf("%d", resA[i][k] + 1);
      }
      puts("");
      for (k = 0; k < res_len[i]; k++) {
        if (k) putchar(' ');
        printf("%d", resB[i][k] + 1);
      }
      puts("");
    }
  }
  return 0;
}
