#include <bits/stdc++.h>
using namespace std;
template <typename type>
type __lcm(type n1, type n2) {
  return n1 * (n2 / __gcd(n1, n2));
}
long long nCr(int n, int r) {
  int f1 = r, f2 = n - r;
  if (f2 > f1) swap(f2, f1);
  long long result = 1;
  for (int i = 1; i <= f2; i++) {
    result *= (i + f1);
    result /= i;
  }
  return result;
}
long long nPr(int n, int r, long long mod = 0) {
  long long result = 1;
  for (int i = n - r + 1; i <= n; i++) {
    result *= i;
    if (mod) result %= mod;
  }
  return result;
}
long long factorial(int n, long long modulo = 0) {
  if (n == 0) return 1;
  if (modulo)
    return (n * factorial(n - 1)) % modulo;
  else
    return n * factorial(n - 1);
}
int *primes = NULL;
bool *isPrime = NULL;
int pidx = 0;
void normal_sieve(int n) {
  n += 5;
  isPrime = new bool[n];
  memset(isPrime, 1, n);
  int sq = sqrt(n);
  isPrime[0] = isPrime[1] = false;
  for (int i = 4; i < n; i += 2) isPrime[i] = false;
  for (int i = 3; i <= sq; i += 2)
    if (isPrime[i])
      for (int j = i * i; j < n; j += (i << 1)) isPrime[j] = false;
  int primeCount = 1;
  for (int i = 3; i < n; i += 2) primeCount += (isPrime[i]);
  primes = new int[primeCount];
  primes[pidx++] = 2;
  for (int i = 3; i < n; i += 2)
    if (isPrime[i]) primes[pidx++] = i;
}
int *isbPrime = NULL;
void bitwise_sieve(int n) {
  n += 5;
  int array_size = (n >> 5);
  isbPrime = new int[array_size];
  memset(isbPrime, 0, n >> 3);
  int sq = sqrt(n);
  (isbPrime[0 >> 5] = isbPrime[0 >> 5] or (1 << (0 % 32)));
  (isbPrime[1 >> 5] = isbPrime[1 >> 5] or (1 << (1 % 32)));
  for (int i = 4; i < 64; i += 2)
    (isbPrime[i >> 5] = isbPrime[i >> 5] or (1 << (i % 32)));
  for (int i = 2; i < array_size; i++) isbPrime[i] = isbPrime[1];
  for (int i = 3; i <= sq; i += 2)
    if (!(isbPrime[i >> 5] & (1 << (i % 32))))
      for (int j = i * i; j < n; j += (i << 1))
        (isbPrime[j >> 5] = isbPrime[j >> 5] or (1 << (j % 32)));
}
void f();
int main() {
  freopen("portals.in", "r", stdin);
  int t = 1;
  cin >> t;
  for (int(i) = (1); (i) <= (t); (i)++) {
    f();
  }
  return 0;
}
bool jawajay(string s, int spos, int epos) {
  bool os = false, oe = false, se = true;
  bool bfound = false;
  for (int i = spos; i >= 0; i--) {
    if (s[i] == '#') bfound = true;
    if (s[i] == 'o' && !bfound) {
      os = true;
      break;
    }
  }
  bfound = false;
  for (int i = spos; i < s.size(); i++) {
    if (s[i] == '#') bfound = true;
    if (s[i] == 'o' && !bfound) {
      os = true;
      break;
    }
  }
  bfound = false;
  for (int i = epos; i >= 0; i--) {
    if (s[i] == '#') bfound = true;
    if (s[i] == 'o' && !bfound) {
      oe = true;
      break;
    }
  }
  bfound = false;
  for (int i = epos; i < s.size(); i++) {
    if (s[i] == '#') bfound = true;
    if (s[i] == 'o' && !bfound) {
      oe = true;
      break;
    }
  }
  for (int i = spos; i <= epos; i++) {
    if (s[i] == '#') {
      se = false;
      break;
    }
  }
  if (se) return true;
  return (os && oe);
}
void f() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int sdx = -1, edx = -1;
  for (int i = 0; i < n; i++) {
    if (s[i] == 's') sdx = i;
    if (s[i] == 'e') edx = i;
  }
  if (sdx > edx) {
    swap(s[sdx], s[edx]);
    swap(sdx, edx);
  }
  string stmp = s;
  if (!jawajay(stmp, sdx, edx)) {
    cout << 0 << '\n';
    return;
  }
  for (int i = sdx; i >= 0; i--) {
    if (stmp[i] == '.') {
      stmp[i] = '#';
      if (!jawajay(stmp, sdx, edx)) {
        cout << 1 << '\n';
        return;
      }
      break;
    }
  }
  stmp = s;
  for (int i = sdx; i < n; i++) {
    if (stmp[i] == '.') {
      stmp[i] = '#';
      if (!jawajay(stmp, sdx, edx)) {
        cout << 1 << '\n';
        return;
      }
      break;
    }
  }
  stmp = s;
  for (int i = edx; i >= 0; i--) {
    if (stmp[i] == '.') {
      stmp[i] = '#';
      if (!jawajay(stmp, sdx, edx)) {
        cout << 1 << '\n';
        return;
      }
      break;
    }
  }
  stmp = s;
  for (int i = edx; i < n; i++) {
    if (stmp[i] == '.') {
      stmp[i] = '#';
      if (!jawajay(stmp, sdx, edx)) {
        cout << 1 << '\n';
        return;
      }
      break;
    }
  }
  stmp = s;
  for (int i = sdx; i >= 0; i--) {
    if (stmp[i] == '.') {
      stmp[i] = '#';
      break;
    }
  }
  for (int i = sdx; i < n; i++) {
    if (stmp[i] == '.') {
      stmp[i] = '#';
      break;
    }
  }
  if (!jawajay(stmp, sdx, edx)) {
    cout << 2 << '\n';
    return;
  }
  stmp = s;
  for (int i = edx; i >= 0; i--) {
    if (stmp[i] == '.') {
      stmp[i] = '#';
      break;
    }
  }
  for (int i = edx; i < n; i++) {
    if (stmp[i] == '.') {
      stmp[i] = '#';
      break;
    }
  }
  if (!jawajay(stmp, sdx, edx)) {
    cout << 2 << '\n';
    return;
  }
  cout << -1 << '\n';
}
