#include <bits/stdc++.h>
using namespace std;
int solve() {
  int n;
  cin >> n;
  int f = 0, c = 0;
  string a;
  cin >> a;
  set<int> s;
  for (int i = n - 1; i >= 0; i--) {
    int x = a[i] - '0';
    if (x != 0) {
      c += x;
      if (i != n - 1 && x != 0) c++;
    }
  }
  cout << c << endl;
  return 0;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
