#include <bits/stdc++.h>
using namespace std;
long long labs(long long a) { return a < 0 ? (-a) : a; }
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
template <typename T>
struct Point {
  T x, y;
  Point() {}
  Point(T xx, T yy) : x(xx), y(yy) {}
};
template <typename T>
bool operator<(const Point<T> &p1, const Point<T> &p2) {
  return p1.x < p2.x || p1.x == p2.x && p1.y < p2.y;
}
const int MAXN = 5;
vector<int> v;
vector<bool> fl;
vector<vector<pair<int, int> > > a[MAXN];
vector<vector<pair<int, int> > > ans;
void Divide(vector<pair<int, int> > &r, int a, vector<pair<int, int> > &to) {
  to.clear();
  if (r.size() == a) {
    copy((r).begin(), (r).end(), back_inserter(to));
    r.clear();
    return;
  }
  for (int(j) = 0; (j) < (a); (j)++) {
    to.push_back(r.back());
    r.pop_back();
  }
  r.push_back(to.front());
  r.back().first = to.back().first;
  to.front().second = to.back().first;
}
vector<pair<int, int> > r;
int main() {
  int n;
  cin >> n;
  v.resize(n);
  fl.resize(n, false);
  for (int(i) = 0; (i) < (n); (i)++) {
    scanf("%d", &v[i]);
  }
  for (int(cur) = 0; (cur) < (n); (cur)++) {
    if (fl[cur]) continue;
    int c1 = cur;
    r.clear();
    do {
      fl[c1] = true;
      r.push_back(make_pair(c1 + 1, v[c1]));
      c1 = v[c1] - 1;
    } while (c1 != cur);
    while (r.size() >= 5) {
      ans.push_back(vector<pair<int, int> >());
      Divide(r, 5, ans.back());
    }
    if (r.size() > 1) {
      a[r.size()].push_back(r);
    }
  }
  while (!a[2].empty() && !a[3].empty()) {
    ans.push_back(a[3].back());
    copy((a[2].back()).begin(), (a[2].back()).end(), back_inserter(ans.back()));
    a[2].pop_back();
    a[3].pop_back();
  }
  while (a[3].size() >= 3) {
    Divide(a[3].back(), 2, r);
    a[2].push_back(a[3].back());
    a[2].push_back(r);
    a[3].pop_back();
    while (!a[2].empty() && !a[3].empty()) {
      ans.push_back(a[3].back());
      copy((a[2].back()).begin(), (a[2].back()).end(),
           back_inserter(ans.back()));
      a[2].pop_back();
      a[3].pop_back();
    }
  }
  while (a[2].size() >= 2) {
    ans.push_back(a[2].back());
    a[2].pop_back();
    copy((a[2].back()).begin(), (a[2].back()).end(), back_inserter(ans.back()));
    a[2].pop_back();
  }
  for (int(i) = 0; (i) < (MAXN); (i)++) {
    for (int(j) = 0; (j) < (a[i].size()); (j)++) {
      ans.push_back(a[i][j]);
    }
  }
  printf("%d\n", ans.size());
  for (int(i) = 0; (i) < (ans.size()); (i)++) {
    printf("%d\n", ans[i].size());
    for (int(j) = 0; (j) < (ans[i].size()); (j)++) {
      printf("%d ", ans[i][j].first);
    }
    printf("\n");
    for (int(j) = 0; (j) < (ans[i].size()); (j)++) {
      printf("%d ", ans[i][j].second);
    }
    printf("\n");
  }
  return 0;
}
