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