#include <bits/stdc++.h>
using namespace std;
#define GG ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main () { GG;
int t; cin>>t;
while(t--) {
int n; string s;
cin>>n>>s;
stack<char> st;
for(int i=0;i<n;i++)
{ if(st.empty())
st.push(s[i]);
else if(s[i]== st.top())
st.push(s[i]);
else
st.pop();
}
cout<<st.size()<<"\n";
}return 0;}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgR0cgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7IGNpbi50aWUoMCk7IGNvdXQudGllKDApOwppbnQgbWFpbiAoKSB7IEdHOwppbnQgdDsgY2luPj50Owp3aGlsZSh0LS0pIHsKaW50IG47IHN0cmluZyBzOwpjaW4+Pm4+PnM7CnN0YWNrPGNoYXI+IHN0OwoKZm9yKGludCBpPTA7aTxuO2krKykKewlpZihzdC5lbXB0eSgpKQoJc3QucHVzaChzW2ldKTsKCWVsc2UgaWYoc1tpXT09IHN0LnRvcCgpKQoJc3QucHVzaChzW2ldKTsKCWVsc2UKCXN0LnBvcCgpOwp9CmNvdXQ8PHN0LnNpemUoKTw8IlxuIjsKfXJldHVybiAwO30=