27 lines
460 B
C++
27 lines
460 B
C++
|
|
#include <bits/stdc++.h>
|
|||
|
|
using namespace std;
|
|||
|
|
/*
|
|||
|
|
2
|
|||
|
|
8 1362
|
|||
|
|
16 3F0
|
|||
|
|
*/
|
|||
|
|
int main() {
|
|||
|
|
int T;
|
|||
|
|
cin >> T;
|
|||
|
|
while (T--) {
|
|||
|
|
int k;
|
|||
|
|
string s;
|
|||
|
|
int res = 0;
|
|||
|
|
cin >> k >> s; // k进制,s是k进制的一个数
|
|||
|
|
for (int i = 0; i < s.size(); i++) {
|
|||
|
|
int x = 0;
|
|||
|
|
if (s[i] >= 'A')
|
|||
|
|
x = s[i] - 'A' + 10;
|
|||
|
|
else
|
|||
|
|
x = s[i] - '0';
|
|||
|
|
res = res * k + x;
|
|||
|
|
}
|
|||
|
|
cout << res << endl;
|
|||
|
|
}
|
|||
|
|
return 0;
|
|||
|
|
}
|