#include <bits/stdc++.h>
using namespace std;
int m, n, j, k, l, i, o, p, __t, A[200000], where[200000];
char ch;
void read(int &a) {
  for (ch = getchar(); (ch < '0' || ch > '9') && (ch != '-'); ch = getchar())
    ;
  if (ch == '-')
    a = 0, __t = -1;
  else
    a = ch - '0', __t = 1;
  for (ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar())
    a = a * 10 + ch - '0';
  a *= __t;
}
vector<vector<int> > S[6], ans;
bool fin[200000];
pair<vector<int>, vector<int> > calc(vector<int> s) {
  pair<vector<int>, vector<int> > ret;
  ret.first.clear();
  ret.second.clear();
  for (int i = 0; i < s.size(); i++) ret.first.push_back(s[i]);
  for (int i = 1; i < s.size(); i++) ret.second.push_back(s[i]);
  ret.second.push_back(s[0]);
  return ret;
}
void solve(int size1, int size2) {
  for (; S[size1].size() && ((S[size2].size() && size2 != 0) || size2 == 0);) {
    if (size1 == size2 && S[size1].size() < 2) return;
    if (size1 == size2 && size1 == 3 && S[3].size() <= S[2].size()) return;
    pair<vector<int>, vector<int> > ret = calc(S[size1][S[size1].size() - 1]);
    S[size1].pop_back();
    if (size1 == size2 && size1 == 3) {
      vector<int> N;
      N.clear();
      int t = S[size2].size() - 1;
      ret.first.push_back(S[size2][t][2]);
      ret.first.push_back(S[size2][t][1]);
      ret.second.push_back(S[size2][t][1]);
      ret.second.push_back(S[size2][t][2]);
      N.push_back(S[size2][t][0]);
      N.push_back(S[size2][t][1]);
      S[2].push_back(N);
      S[size2].pop_back();
    } else if (size2 != 0) {
      int t = S[size2].size() - 1;
      ret.first.push_back(S[size2][t][0]);
      ret.first.push_back(S[size2][t][1]);
      ret.second.push_back(S[size2][t][1]);
      ret.second.push_back(S[size2][t][0]);
      S[size2].pop_back();
    }
    ans.push_back(ret.first);
    ans.push_back(ret.second);
  }
}
int main() {
  read(m);
  for (int i = 1; i <= m; i++) read(A[i]), where[A[i]] = i;
  for (int i = 1; i <= m; i++)
    if (A[i] != i && !fin[i]) {
      vector<int> now;
      now.clear();
      now.push_back(i);
      int root = i;
      for (int P = A[i]; P != i; P = A[P]) now.push_back(P), fin[P] = 1;
      for (; now.size() >= 5;) {
        vector<int> ret, print;
        ret.clear();
        print.clear();
        int k = now.size() - 5;
        for (int j = now.size() - 1; j >= k; j--) ret.push_back(now[j]);
        print.push_back(now[now.size() - 5]);
        for (int j = now.size() - 1; j > k; j--) print.push_back(now[j]);
        for (int j = 1; j <= 4; j++) now.pop_back();
        ans.push_back(ret);
        ans.push_back(print);
      }
      S[now.size()].push_back(now);
    }
  solve(4, 0);
  solve(3, 2);
  solve(3, 3);
  solve(3, 2);
  solve(3, 0);
  solve(2, 2);
  solve(2, 0);
  printf("%d\n", ans.size() / 2);
  for (int i = 0; i < ans.size(); i += 2) {
    printf("%d\n", ans[i].size());
    for (int j = 0; j < ans[i].size(); j++) printf("%d ", ans[i][j]);
    printf("\n");
    for (int j = 0; j < ans[i + 1].size(); j++) printf("%d ", ans[i + 1][j]);
    printf("\n");
  }
}
