#include <bits/stdc++.h>   using namespace std;   void _print(long long t) { cerr << t; }   void _print(int t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   template <class T, class V>   void _print(T a[], V sz);   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<   ->  ;     _print(p.second);     cerr <<  }  << endl;   }   template <class T, class V>   void _print(T a[], V sz) {     for (V i = 0; i < sz; i++) {       _print(a[i]);       cerr <<    ;     }     cerr << endl;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ]  << endl;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ]  << endl;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ]  << endl;   }   void _printall(long long t) { cout << t; }   void _printall(int t) { cout << t; }   void _printall(string t) { cout << t; }   void _printall(char t) { cout << t; }   void _printall(long double t) { cout << t; }   void _printall(double t) { cout << t; }   void _printall(unsigned long long t) { cout << t; }   template <class T, class V>   void _printall(T a[], V sz);   template <class T, class V>   void _printall(pair<T, V> p);   template <class T>   void _printall(vector<T> v);   template <class T>   void _printall(set<T> v);   template <class T, class V>   void _printall(map<T, V> v);   template <class T>   void _printall(multiset<T> v);   template <class T, class V>   void _printall(T a[], V sz) {     for (V i = 0; i < sz; i++) {       _printall(a[i]);       cout <<    ;     }     cout << endl;   }   template <class T, class V>   void _printall(pair<T, V> p) {     _printall(p.ff);     cout <<  , ;     _printall(p.ss);   }   template <class T>   void _printall(vector<T> v) {     for (T i : v) {       _printall(i);       cout <<    ;     }     cout << endl;   }   template <class T>   void _printall(set<T> v) {     for (T i : v) {       _printall(i);       cout <<    ;     }     cout << endl;   }   template <class T>   void _printall(multiset<T> v) {     for (T i : v) {       _printall(i);       cout <<    ;     }     cout << endl;   }   template <class T, class V>   void _printall(map<T, V> v) {     for (auto i : v) {       _printall(i);       cout <<    ;     }     cout << endl;   }   long long MAXN = 200001;   long long spf[200001];   void sieve() {     spf[1] = 1;     for (int i = 2; i < MAXN; i++) {       spf[i] = i;     }     for (long long i = 4; i < MAXN; i += 2) {       spf[i] = 2;     }     for (long long i = 3; i * i < MAXN; i++) {       if (spf[i] == i) {         for (long long j = i * i; j < MAXN; j += i) {           if (spf[j] == j) spf[j] = i;         }       }     }   }   vector<long long> getFactorization(long long x) {     vector<long long> ret;     while (x != 1) {       ret.push_back(spf[x]);       x = x / spf[x];     }     return ret;   }   void solve() {     long long n;     cin >> n;     string s;     cin >> s;     vector<int> pre;     int cnt = 0;     for (int i = 0; i < n; i++) {       pre.push_back(1);     }     for (int i = n - 2; i >= 0; i--) {       if (s[i] == s[i + 1]) {         pre[i] = pre[i + 1] + 1;       }     }     reverse(pre.begin(), pre.end());     vector<int> fin;     for (int i = 0; i < pre.size() - 1; i++) {       if (pre[i] == 1 && pre[i + 1] == 1) {         fin.push_back(pre[i]);       } else if (pre[i] >= 1 && pre[i + 1] == 1) {         fin.push_back(pre[i]);       }     }     if (pre[n - 1] >= 1) {       fin.push_back(pre[n - 1]);     }     int ind1 = fin.size() - 1;     int ind2 = fin.size() - 1;     while (pre.size() != 0 && ind1 >= 0 && ind2 >= 0) {       if (fin[ind1] > 1) {         cnt++;         fin.pop_back();         if (ind2 == ind1) {           ind2--;         }         ind1--;       } else {         while (fin[ind2] == 1) {           ind2--;         }         if (ind2 < 0) {           break;         } else {           cnt++;           fin[ind2]--;           fin.pop_back();           ind1--;         }       }     }     if (pre.size() != 0) {       cnt += (fin.size() + 1) / 2;     }     cout << cnt << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl;     return 0;   }   