#include <bits/stdc++.h>
using namespace std;
int t, n, i, f, a[200008];
int main() {
  for (scanf("%d", &t); t--; printf("%d\n", f < 2 ? f : 2), i = f = 0)
    for (scanf("%d", &n); i++ < n;
         scanf("%d", a + i), f += a[i] != i && a[i - 1] + 1 == i)
      ;
  exit(0);
}
