#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int NMAX = 200 + 10;
int n;
vector<int> a;
vector<bool> us;
vector<vector<int> > twoc;
vector<vector<int> > threec;
vector<vector<int> > ans;
void readData() {
  scanf("%d", &n);
  a.resize(n);
  for (int i = 0; i < (int)(n); ++i) {
    scanf("%d", &a[i]);
    a[i]--;
  }
  us.resize(n, false);
}
void put_ans(vector<int>& v) {
  ans.push_back(v);
  ans.push_back(vector<int>());
  for (int i = 0; i < (int)(v.size()); ++i) {
    ans.back().push_back(v[(i + 1) % v.size()]);
  }
}
void put_ans(vector<int>& v1, vector<int>& v2) {
  ans.push_back(v1);
  for (int i = 0; i < (int)(v2.size()); ++i) {
    ans.back().push_back(v2[i]);
  }
  ans.push_back(vector<int>());
  for (int i = 0; i < (int)(v1.size()); ++i) {
    ans.back().push_back(v1[(i + 1) % v1.size()]);
  }
  for (int i = 0; i < (int)(v2.size()); ++i) {
    ans.back().push_back(v2[(i + 1) % v2.size()]);
  }
}
void solution() {
  for (int i = 0; i < (int)(n); ++i) {
    if (us[i]) continue;
    vector<int> tmp;
    int idx = i;
    while (us[idx] == false) {
      tmp.push_back(idx);
      us[idx] = true;
      idx = a[idx];
    }
    while (tmp.size() >= 4) {
      vector<int> tmp2;
      for (int q = 0; q < (int)(5); ++q) {
        if (tmp.size() == 0) break;
        tmp2.push_back(tmp.back());
        tmp.pop_back();
      }
      reverse(tmp2.begin(), tmp2.end());
      if (tmp.size() != 0) {
        tmp.push_back(tmp2[0]);
      }
      put_ans(tmp2);
    }
    if (tmp.size() == 2) twoc.push_back(tmp);
    if (tmp.size() == 3) threec.push_back(tmp);
  }
  while (twoc.size() > 0 || threec.size() > 0) {
    if (twoc.size() > 0 && threec.size() > 0) {
      put_ans(twoc.back(), threec.back());
      twoc.pop_back();
      threec.pop_back();
      continue;
    }
    if (threec.size() >= 2) {
      vector<int> tmp = threec.back();
      threec.pop_back();
      vector<int> tmp2;
      tmp2.push_back(tmp[0]);
      tmp2.push_back(a[tmp[0]]);
      int idx1 = tmp[0], idx2 = a[tmp[0]];
      swap(a[idx1], a[idx2]);
      vector<int> tmp3;
      for (int i = 0; i < (int)(tmp.size()); ++i) {
        if (tmp[i] == a[tmp[i]]) continue;
        tmp3.push_back(tmp[i]);
      }
      swap(a[idx1], a[idx2]);
      put_ans(threec.back(), tmp2);
      threec.pop_back();
      twoc.push_back(tmp3);
      continue;
    }
    if (twoc.size() >= 2) {
      vector<int> tmp = twoc.back();
      twoc.pop_back();
      vector<int> tmp2 = twoc.back();
      twoc.pop_back();
      put_ans(tmp, tmp2);
      continue;
    }
    if (threec.size() == 1) {
      put_ans(threec.back());
      threec.pop_back();
    }
    if (twoc.size() == 1) {
      put_ans(twoc.back());
      twoc.pop_back();
    }
  }
}
void writeData() {
  printf("%d\n", ans.size() / 2);
  for (int i = 0; i < ans.size(); i += 2) {
    printf("%d\n", ans[i].size());
    map<int, int> pos;
    for (int j = 0; j < (int)(ans[i].size()); ++j) {
      printf("%d ", ans[i][j] + 1);
      pos[ans[i][j]] = a[ans[i][j]];
    }
    printf("\n");
    for (int j = 0; j < (int)(ans[i + 1].size()); ++j) {
      printf("%d ", ans[i + 1][j] + 1);
      a[ans[i + 1][j]] = pos[ans[i][j]];
    }
    printf("\n");
  }
}
int main() {
  readData();
  solution();
  writeData();
  return 0;
}
