//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define dd double
#define ld long double
#define ull unsigned long long
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define el "\n"
#define Arwa ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fix(x) cout << fixed << setprecision(x)
#define all(v) v.begin(),v.end()
void file()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
bool prime(int n) {
if (n == 2) return true;
if (n % 2 == 0 || n == 1) return false;
for (int i = 3; i * i <= n; i += 2)
if (n % i == 0) return false;
return true;
}
//Here We Go Again
int32_t main()
{
Arwa
//file();
int t=1;
cin>>t;
while(t--)
{
int x,l=0;
cin>>x;
string s,c;
int cl,sl;
cin>>s;
while(l!=x&&l!=s.length())
{
l++;
cl=l;
sl=s.length()-l;
c=s.substr(l,sl);
s=s.substr(0,cl);
int st=s[l-1]-'0';
while(st--)
{
s+=c;
}
}
cout<<s.length();
}
return 0;
}
Ly8jaW5jbHVkZSA8ZXh0L3BiX2RzL2Fzc29jX2NvbnRhaW5lci5ocHA+IAovLyNpbmNsdWRlIDxleHQvcGJfZHMvdHJlZV9wb2xpY3kuaHBwPiAKLy91c2luZyBuYW1lc3BhY2UgX19nbnVfcGJkczsgCi8vI2RlZmluZSBvcmRlcmVkX3NldCB0cmVlPGludCwgbnVsbF90eXBlLGxlc3M8aW50PiwgcmJfdHJlZV90YWcsdHJlZV9vcmRlcl9zdGF0aXN0aWNzX25vZGVfdXBkYXRlPiAKI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUga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AgIHsKICAgICAgaW50IHgsbD0wOwogICAgICBjaW4+Png7CiAgICAgIHN0cmluZyBzLGM7CiAgICAgIGludCBjbCxzbDsKICAgICAgY2luPj5zOwogICAgICB3aGlsZShsIT14JiZsIT1zLmxlbmd0aCgpKQogICAgICB7CiAgICAgICAgbCsrOwogICAgICAgIGNsPWw7CiAgICAgICAgc2w9cy5sZW5ndGgoKS1sOwogICAgICAgIGM9cy5zdWJzdHIobCxzbCk7CiAgICAgICAgcz1zLnN1YnN0cigwLGNsKTsgCiAgICAgICAgaW50IHN0PXNbbC0xXS0nMCc7CiAgICAgICAgd2hpbGUoc3QtLSkKICAgICAgICB7CiAgICAgICAgcys9YzsKICAgICAgICB9CiAgICAgIH0KICAgICAgY291dDw8cy5sZW5ndGgoKTsKICAgIH0KICAgIHJldHVybiAwOwp9Cg==