#include <bits/stdc++.h>
using namespace std;
vector<int> v, v_copy;
int main() {
  int n, x, counter = 0;
  cin >> n;
  for (int test = 1; test <= n; test++) {
    cin >> x;
    int a;
    bool t = true;
    for (int i = 1; i <= x; i++) {
      cin >> a;
      if (a != i && t) {
        counter++;
      }
      t = (a == i);
    }
    if (counter > 2) {
      counter = 2;
    }
    cout << counter << endl;
    counter = 0;
  }
  return 0;
}
