#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
  T t;
  while (a && b) t = a, a = b % a, b = t;
  return a + b;
}
template <class T>
inline T power(T a, int p) {
  T r = T(1);
  while (p) {
    if (p & 1) r = r * a;
    a = a * a;
    p >>= 1;
  }
  return r;
}
template <class T>
T extgcd(T a, T b, T& x, T& y) {
  if (b == 0) return x = 1, y = 0, a;
  T x1, y1, g;
  g = extgcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - a / b * y1;
  return g;
}
template <class T>
inline T Floor(T a, T b) {
  if (b < 0) a = -a, b = -b;
  if (a < 0) return (a - b + 1) / b;
  return a / b;
}
template <class T>
inline T Ceil(T a, T b) {
  if (b < 0) a = -a, b = -b;
  if (a < 0) return a / b;
  return (a + b - 1) / b;
}
int N, M, K;
int a[111111];
bool w[111111];
vector<vector<int> > sol[6];
vector<pair<vector<int>, vector<int> > > gsol;
void solve(vector<int>& v) {
  int n = ((int)v.size());
  int last = n - 1;
  while (last >= 0) {
    int cur = max(0, last - 4);
    vector<int> tmp;
    for (int j = cur; j <= last; ++j) tmp.push_back(v[j]);
    sol[((int)tmp.size())].push_back(tmp);
    if (cur == 0) {
      last = -1;
    } else {
      last = cur;
    }
  }
}
void output(vector<int>& v, int s) {
  for (int i = 0; i < s; ++i) printf("%d%c", v[i], i == s - 1 ? '\n' : ' ');
}
vector<int> shiftl(vector<int>& v) {
  int ss = ((int)v.size());
  vector<int> tmp;
  for (int j = 1; j < ss; ++j) tmp.push_back(v[j]);
  tmp.push_back(v[0]);
  return tmp;
}
int s[6];
int main() {
  scanf("%d", &N);
  int tmp;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &tmp);
    a[i + 1] = tmp;
  }
  vector<vector<int> > v;
  for (int i = 1; i < N + 1; ++i) {
    if (w[i] || i == a[i]) continue;
    vector<int> t;
    int cur = a[i];
    t.push_back(i);
    while (cur != i) {
      t.push_back(cur);
      w[cur] = true;
      cur = a[cur];
      w[cur] = true;
    }
    v.push_back(t);
  }
  for (int i = 0; i < ((int)v.size()); ++i) {
    solve(v[i]);
  }
  for (int i = 0; i < ((int)sol[5].size()); ++i)
    gsol.push_back(make_pair(sol[5][i], shiftl(sol[5][i])));
  int mn = min(((int)sol[3].size()) - s[3], ((int)sol[2].size()) - s[2]);
  for (int i = 0; i < mn; ++i) {
    vector<int>& s3 = sol[3][s[3] + i];
    vector<int>& s2 = sol[2][s[2] + i];
    vector<int> ss3 = shiftl(s3);
    vector<int> ss2 = shiftl(s2);
    for (int j = 0; j < 2; ++j) {
      s3.push_back(s2[j]);
      ss3.push_back(ss2[j]);
    }
    gsol.push_back(make_pair(s3, ss3));
  }
  s[3] += mn;
  s[2] += mn;
  mn = min(((int)sol[4].size()) - s[4],
           min(((int)sol[3].size()) - s[3], ((int)sol[2].size()) - s[2]));
  for (int i = 0; i < mn; ++i) {
    vector<int>& cur = sol[4][s[4] + i];
    vector<int> t3 = vector<int>(cur.begin() + 1, cur.end());
    vector<int> tt3 = shiftl(t3);
    vector<int>& e2 = sol[2][s[2] + i];
    vector<int> ee2 = shiftl(e2);
    for (int j = 0; j < 2; ++j) {
      t3.push_back(e2[j]);
      tt3.push_back(ee2[j]);
    }
    vector<int> t2 = vector<int>(cur.begin(), cur.begin() + 2);
    vector<int> tt2 = shiftl(t2);
    vector<int>& e3 = sol[3][s[3] + i];
    vector<int> ee3 = shiftl(e3);
    for (int j = 0; j < 3; ++j) {
      t2.push_back(e3[j]);
      tt2.push_back(ee3[j]);
    }
    gsol.push_back(make_pair(t3, tt3));
    gsol.push_back(make_pair(t2, tt2));
  }
  s[2] += mn;
  s[3] += mn;
  s[4] += mn;
  for (int i = s[4]; i < ((int)sol[4].size()); ++i)
    gsol.push_back(make_pair(sol[4][i], shiftl(sol[4][i])));
  int t3 = (((int)sol[3].size()) - s[3]) / 3;
  for (int i = 0; i < t3; ++i) {
    vector<int>& c1 = sol[3][s[3] + i * 3 + 0];
    vector<int>& c2 = sol[3][s[3] + i * 3 + 1];
    vector<int>& c3 = sol[3][s[3] + i * 3 + 2];
    vector<int> t1 = vector<int>(c1.begin() + 1, c1.end());
    vector<int> tt1 = shiftl(t1);
    vector<int> cc2 = shiftl(c2);
    for (int j = 0; j < 3; ++j) {
      t1.push_back(c2[j]);
      tt1.push_back(cc2[j]);
    }
    vector<int> t2 = vector<int>(c1.begin(), c1.begin() + 2);
    vector<int> tt2 = shiftl(t2);
    vector<int> cc3 = shiftl(c3);
    for (int j = 0; j < 3; ++j) {
      t2.push_back(c3[j]);
      tt2.push_back(cc3[j]);
    }
    gsol.push_back(make_pair(t1, tt1));
    gsol.push_back(make_pair(t2, tt2));
  }
  s[3] += t3 * 3;
  for (int i = s[3]; i < ((int)sol[3].size()); ++i)
    gsol.push_back(make_pair(sol[3][i], shiftl(sol[3][i])));
  int mn2 = (((int)sol[2].size()) - s[2]) / 2;
  for (int i = 0; i < mn2; ++i) {
    vector<int>& s1 = sol[2][s[2] + i * 2];
    vector<int>& s2 = sol[2][s[2] + i * 2 + 1];
    vector<int> ss1 = shiftl(s1);
    vector<int> ss2 = shiftl(s2);
    for (int j = 0; j < 2; ++j) {
      s1.push_back(s2[j]);
      ss1.push_back(ss2[j]);
    }
    gsol.push_back(make_pair(s1, ss1));
  }
  s[2] += mn2 * 2;
  for (int i = s[2]; i < ((int)sol[2].size()); ++i)
    gsol.push_back(make_pair(sol[2][i], shiftl(sol[2][i])));
  printf("%d\n", ((int)gsol.size()));
  for (int i = 0; i < ((int)gsol.size()); ++i) {
    pair<vector<int>, vector<int> >& cur = gsol[i];
    int ss = ((int)cur.first.size());
    printf("%d\n", ss);
    output(cur.first, ss);
    output(cur.second, ss);
  }
  return 0;
}
