#include<iostream> #define int long long using namespace std; using PII = pair<int, int>; int t, n; string k; signed main() { // ios::sync_with_stdio(0); cin >> t; while (t--) { int temp = 0; cin >> n >> k; temp = stoi(k, 0, n); cout << temp << endl; } return 0; }