#include <bits/stdc++.h>
using namespace std;
const int maxn = 110000;
int a[maxn], nov[maxn];
vector<vector<int> > group[10];
struct point {
  vector<int> ans[2];
};
vector<point> ans;
void dfs(int i, vector<int> &tmp, int in) {
  nov[i] = 0;
  tmp.push_back(i);
  if (a[i] == in) return;
  dfs(a[i], tmp, in);
}
void gao(vector<int> &tmp, int k) {
  if (ans.size() == 0 || ans.back().ans[0].size() + k > 5)
    ans.resize(ans.size() + 1);
  if (k == tmp.size()) {
    for (int i = 0; i < tmp.size(); i++) {
      ans.back().ans[1].push_back(tmp[(i + 1) % tmp.size()]);
      ans.back().ans[0].push_back(tmp[i]);
    }
    tmp.clear();
  } else {
    for (int i = tmp.size() - k; i < tmp.size() - 1; i++) {
      ans.back().ans[1].push_back(tmp[i + 1]);
      ans.back().ans[0].push_back(tmp[i]);
    }
    ans.back().ans[1].push_back(tmp[tmp.size() - k]);
    ans.back().ans[0].push_back(tmp.back());
    for (int i = 0; i < k - 1; i++) tmp.pop_back();
  }
}
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    group[2].clear();
    group[3].clear();
    vector<int> tmp;
    ans.clear();
    for (int i = 1; i <= n; i++) nov[i] = 1;
    for (int i = 1; i <= n; i++)
      if (nov[i]) {
        tmp.clear();
        dfs(i, tmp, i);
        while (tmp.size() >= 4) gao(tmp, min(5, (int)tmp.size()));
        if (tmp.size() == 2 || tmp.size() == 3)
          ;
        group[tmp.size()].push_back(tmp);
      }
    while (group[2].size() > 0 || group[3].size() > 0) {
      if (group[2].size() > 0 && group[3].size() > 0) {
        gao(group[2].back(), 2);
        group[2].pop_back();
        gao(group[3].back(), 3);
        group[3].pop_back();
      } else if (group[3].size() >= 2) {
        gao(group[3].back(), 3);
        group[3].pop_back();
        gao(group[3].back(), 2);
        group[2].push_back(group[3].back());
        group[3].pop_back();
      } else if (group[2].size() >= 2) {
        gao(group[2].back(), 2);
        group[2].pop_back();
        gao(group[2].back(), 2);
        group[2].pop_back();
      } else {
        if (group[2].size() > 0) {
          gao(group[2].back(), 2);
          group[2].pop_back();
        } else {
          gao(group[3].back(), 3);
          group[3].pop_back();
        }
      }
    }
    printf("%d\n", (int)ans.size());
    for (int i = 0; i < ans.size(); i++) {
      printf("%d\n", ans[i].ans[0].size());
      for (int j = 0; j < 2; j++) {
        for (int p = 0; p < ans[i].ans[j].size() - 1; p++)
          printf("%d ", ans[i].ans[j][p]);
        printf("%d\n", ans[i].ans[j].back());
      }
    }
  }
}
