#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  while (cin >> t) {
    while (t--) {
      int n;
      string s;
      cin >> n >> s;
      int res = 0;
      for (int i = 0; i < n; i++) {
        if (s[i] == '0') continue;
        if (i == n - 1)
          res = res + (int)(s[i] - '0');
        else
          res = res + (int)(s[i] - '0') + 1;
      }
      cout << res << endl;
    }
  }
  return 0;
}
