#include <bits/stdc++.h>
using namespace std;
bool mark[100100];
int pos[100100];
queue<int> sobra[5];
int main() {
  int n;
  int res = 0;
  vector<int> answer;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &pos[i]);
    mark[i] = false;
  }
  for (int i = 1; i <= n; i++) {
    if (pos[i] != i && !mark[i]) {
      int atual = i;
      queue<int> ciclo;
      do {
        mark[atual] = true;
        ciclo.push(atual);
        atual = pos[atual];
      } while (atual != i);
      while (ciclo.size() >= 4) {
        res++;
        int k = min(5, (int)ciclo.size());
        answer.push_back(k);
        for (int j = 0; j < k; j++) {
          answer.push_back(ciclo.front());
          ciclo.pop();
        }
        int size = answer.size();
        for (int j = k - 1; j >= 1; j--) {
          answer.push_back(answer[size - j]);
        }
        answer.push_back(answer[size - k]);
        ciclo.push(answer[size - k]);
      }
      if (ciclo.size() > 1) {
        int k = ciclo.size();
        while (!ciclo.empty()) {
          sobra[k].push(ciclo.front());
          ciclo.pop();
        }
      }
    }
  }
  while (sobra[3].size() > 0) {
    int k = 3;
    int tipo;
    res++;
    if (sobra[2].size() > 0) {
      k += 2;
      tipo = 2;
    } else if (sobra[3].size() > 3) {
      k += 2;
      tipo = 3;
    }
    answer.push_back(k);
    for (int i = 0; i < 3; i++) {
      answer.push_back(sobra[3].front());
      sobra[3].pop();
    }
    if (k > 3) {
      for (int i = 0; i < 2; i++) {
        answer.push_back(sobra[tipo].front());
        sobra[tipo].pop();
      }
      if (tipo == 3) {
        sobra[2].push(answer[answer.size() - 2]);
        sobra[2].push(sobra[3].front());
        sobra[3].pop();
      }
    }
    int size = answer.size();
    if (k == 3) {
      answer.push_back(answer[size - 2]);
      answer.push_back(answer[size - 1]);
      answer.push_back(answer[size - 3]);
    } else {
      answer.push_back(answer[size - 4]);
      answer.push_back(answer[size - 3]);
      answer.push_back(answer[size - 5]);
      answer.push_back(answer[size - 1]);
      answer.push_back(answer[size - 2]);
    }
  }
  while (sobra[2].size() > 0) {
    int k = 2;
    res++;
    if (sobra[2].size() > 2) {
      k += 2;
    }
    answer.push_back(k);
    for (int i = 0; i < 2; i++) {
      answer.push_back(sobra[2].front());
      sobra[2].pop();
    }
    if (k > 2) {
      for (int i = 0; i < 2; i++) {
        answer.push_back(sobra[2].front());
        sobra[2].pop();
      }
    }
    int size = answer.size();
    if (k == 2) {
      answer.push_back(answer[size - 1]);
      answer.push_back(answer[size - 2]);
    } else {
      answer.push_back(answer[size - 3]);
      answer.push_back(answer[size - 4]);
      answer.push_back(answer[size - 1]);
      answer.push_back(answer[size - 2]);
    }
  }
  printf("%d\n", res);
  for (int i = 0; i < answer.size(); i++) {
    printf("%d\n", answer[i]);
    for (int j = 0; j < answer[i]; j++) {
      if (j > 0) printf(" ");
      printf("%d", answer[i + j + 1]);
    }
    printf("\n");
    for (int j = 0; j < answer[i]; j++) {
      if (j > 0) printf(" ");
      printf("%d", answer[i + answer[i] + j + 1]);
    }
    printf("\n");
    i += 2 * answer[i];
  }
  return 0;
}
