#include <bits/stdc++.h>
using namespace std;
int digitsSum(long long n) {
  int sum = 0;
  while (n != 0) {
    sum = sum + (n % 10);
    n = n / 10;
  }
  return sum;
}
int countPositive(long long n) {
  int positive = 0;
  while (n != 0) {
    if (n % 10 != 0) {
      positive++;
    }
    n = n / 10;
  }
  return positive;
}
int main() {
  int testCount;
  cin >> testCount;
  int n;
  for (int test = 0; test < testCount; test++) {
    cin >> n;
    char arr[n];
    int count = 0;
    int digit;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      digit = (int)arr[i] - 48;
      if (digit != 0) {
        count++;
      }
      count = count + digit;
    }
    int lastDigit = (int)arr[n - 1] - 48;
    if (lastDigit != 0) {
      count = count - 1;
    }
    cout << count << endl;
  }
  return 0;
}
