#include <bits/stdc++.h>
using namespace std;
#define int long long
int a[100011];
int maxx;
char s[1000011];
int d;
int f;
char c;
int g;
signed main()
{
int n;
cin >> n;
while(n --)
{
d = 0;
g = 0;
int x;
cin >> x;
for(int i = 0; i < x; i++) {cin >> s[i];}
// for(int i = 0; i < x; i++)
// {
// for(int j = i + 1; j < x; j++)
// if(s[i] == s[j]) {f = 1;break;}
// if(f == 1) break;
// }
// if(f == 0) {
// cout << x << endl;
// continue;
// }
// for(int i = 1; ; i++)
// {
// if(i == 3) i = 1;
// if(x >= i)
// x -= i, d++;
// else break;
// }
while(g <= x)
{
if(s[g] == s[g + 1] && g + 1 <= x){ d += 2 ,g+=3;continue;}
else d ++ , g ++;
}
cout << d - 1 << endl;
}
return 0;
}
/*
3
ab3
d->a,b,d
ass->a,ss
asds->a,s,d,s
assd->a,ss,d
asds->a,s,d,s
pppqqppppq->p,pp,q,qp,p,pp,q
*/
思路是:如果字符与前面的不同,就把后一个字符加进来,之后,再去一个字符。