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