#include <bits/stdc++.h>
using namespace std;
const int maxn = 110000;
vector<int> pos;
vector<vector<int> > as[4], ans1, ans2;
int n, m;
bool vis[maxn];
int main() {
  cin >> n;
  for (int i = (0); i <= (n - 1); i++) {
    int x;
    scanf("%d", &x);
    pos.push_back(x - 1);
  }
  memset(vis, 0, sizeof(vis));
  for (int i = (0); i <= (n - 1); i++)
    if (!vis[i]) {
      vector<int> a;
      int x = i;
      do {
        a.push_back(x);
        vis[x] = 1;
        x = pos[x];
      } while (x != i);
      while ((m = a.size()) > 3) {
        vector<int> tmp1, tmp2;
        int t = min(5, m);
        for (int j = (m - t); j <= (m - 1); j++) tmp1.push_back(a[j]);
        for (int j = (m - t); j <= (m - 1); j++)
          tmp2.push_back(a[(j == m - 1) ? m - t : j + 1]);
        ans1.push_back(tmp1);
        ans2.push_back(tmp2);
        for (int j = (1); j <= (t - 1); j++) a.pop_back();
      }
      if (a.size() > 1) as[a.size()].push_back(a);
    }
  while (as[2].size() < as[3].size()) {
    vector<int> tmp1, tmp2;
    for (int j = (0); j <= (2); j++) tmp1.push_back(as[3].back()[j]);
    for (int j = (0); j <= (2); j++) tmp2.push_back(as[3].back()[(j + 1) % 3]);
    as[3].pop_back();
    if (as[3].size()) {
      for (int j = (1); j <= (2); j++) tmp1.push_back(as[3].back()[j]);
      for (int j = (1); j <= (2); j++) tmp2.push_back(as[3].back()[3 - j]);
      vector<int> t;
      t.push_back(as[3].back()[0]);
      t.push_back(as[3].back()[1]);
      as[2].push_back(t);
      as[3].pop_back();
    }
    ans1.push_back(tmp1);
    ans2.push_back(tmp2);
  }
  while (as[3].size()) {
    vector<int> tmp1, tmp2;
    for (int j = (0); j <= (1); j++)
      tmp1.push_back(as[2].back()[j]), tmp2.push_back(as[2].back()[1 - j]);
    for (int j = (0); j <= (2); j++)
      tmp1.push_back(as[3].back()[j]),
          tmp2.push_back(as[3].back()[(j + 1) % 3]);
    as[2].pop_back();
    as[3].pop_back();
    ans1.push_back(tmp1);
    ans2.push_back(tmp2);
  }
  while (as[2].size()) {
    vector<int> tmp1, tmp2;
    for (int j = (0); j <= (1); j++)
      tmp1.push_back(as[2].back()[j]), tmp2.push_back(as[2].back()[1 - j]);
    as[2].pop_back();
    if (as[2].size() != 0) {
      for (int j = (0); j <= (1); j++)
        tmp1.push_back(as[2].back()[j]), tmp2.push_back(as[2].back()[1 - j]);
      as[2].pop_back();
    }
    ans1.push_back(tmp1);
    ans2.push_back(tmp2);
  }
  cout << ans1.size() << endl;
  int t = (ans1.size()) - 1;
  for (int i = (0); i <= (t); i++) {
    printf("%d\n", ans1[i].size());
    for (int j = (0); j <= (ans1[i].size() - 1); j++)
      printf("%d ", ans1[i][j] + 1);
    cout << endl;
    for (int j = (0); j <= (ans1[i].size() - 1); j++)
      printf("%d ", ans2[i][j] + 1);
    cout << endl;
  }
  return 0;
}
