#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long N = 8e2;
long long summation(long long x) {
  return (((x % mod) * ((x + 1) % mod)) / 2) % mod;
}
vector<bool> prime(N + 1, 1);
void sieve() {
  prime[1] = 0;
  for (long long i = 2; i * i <= N; i++) {
    if (prime[i] == 1) {
      for (long long j = i * i; j <= N; j += i) {
        prime[j] = 0;
      }
    }
  }
}
long long binpow(long long a, long long b, long long M) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % M;
    b >>= 1;
    a = (a * a) % mod;
  }
  return res;
}
long long inverse(long long a, long long M) { return binpow(a, M - 2, M); }
vector<long long> fact(N + 1);
vector<long long> inv(N);
void invmod() {
  inv[N - 1] = inverse(fact[N - 1], mod);
  for (long long i = N - 1; i > 0; i--) {
    inv[i - 1] = (i * inv[i]) % mod;
  }
}
void factorial() {
  fact[0] = 1;
  for (long long i = 1; i <= N; i++) {
    fact[i] = (i * fact[i - 1]) % mod;
  }
}
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  return (a.second < b.second);
}
vector<long long> squ(N);
void square() {
  for (long long i = 1; i < N; i++) squ[i] = i * i;
}
void solve() {
  long long n, m, k, l, x, mx, mn;
  cin >> n;
  string second;
  cin >> second;
  long long cnt = 0;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    if (second[i] == '0')
      sum++;
    else
      cnt += (second[i] - '0');
  }
  if (second[n - 1] != '0') cnt--;
  cnt += n - sum;
  cout << cnt << endl;
}
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
