#include<iostream>
#include<string>
using namespace std;
int n, s;
string a;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
int da[4] = { 0 }, xiao[4] = { 0 };
cin >> s >> a;
for (int j = 0; j < s; j++) {
if (a[j] == 'd')xiao[0]++;
if (a[j] == 'f')xiao[1] += xiao[0];
if (a[j] == 's')xiao[2] += xiao[1];
if (a[j] == 'D')da[0]++;
if (a[j] == 'F')da[1] += da[0];
if (a[j] == 'S')da[2] += da[1];
}
cout << (xiao[2] ? 1 : 0) << " " << (da[2] ? 1 : 0) << endl;
}
return 0;
}
map<long long, long long>m;
int flagl = 0, flagr = 0;
cin >> num;
for (int i = 1; i <= num; i++) {
cin >> r >> c;
if (!m[c]) {
m[c] = r;
if (c < 0) {
if ((m[c - 1] && m[c - 1] != m[c]) || (m[c + 1] && m[c + 1] != m[c])) {
flagl = 2;
}
else {
flagl = max(1, flagl);
}
}
if (c > 0) {
if ((c-1>=1e9&&m[c - 1] && m[c - 1] != m[c]) || (c+1<=1e9&&m[c + 1] && m[c + 1] != m[c])) {
flagr = 2;
}
else {
flagr = max(1, flagr);
}
}
}
else {
if (c < 0)flagl = 2;
if (c > 0)flagr = 2;
}
}
if (!m[0]){
cout<<min(1+min(2-flagr,((m[1]&&m[1]==1)?0:1))+min(2-flagl,((m[-1]&&m[-1]==1)?0:1)),4-flagl-flagr)<<endl;
}
if (m[0]) {
//cout<<222<<endl;
cout << min(2-flagl,1)+min(2-flagr,1) << endl;
}