#include <bits/stdc++.h>
using namespace std;
using cd = complex<double>;
const double PI = acos(-1);
void fft(vector<cd> & a, bool invert) {
int n = a.size();
if (n == 1)
return;
vector<cd> a0(n / 2), a1(n / 2);
for (int i = 0; 2 * i < n; i++) {
a0[i] = a[2*i];
a1[i] = a[2*i+1];
}
fft(a0, invert);
fft(a1, invert);
double ang = 2 * PI / n * (invert ? -1 : 1);
cd w(1), wn(cos(ang), sin(ang));
for (int i = 0; 2 * i < n; i++) {
a[i] = a0[i] + w * a1[i];
a[i + n/2] = a0[i] - w * a1[i];
if (invert) {
a[i] /= 2;
a[i + n/2] /= 2;
}
w *= wn;
}
}
vector<int> multiply(vector<int> const& a, vector<int> const& b) {
vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
int n = 1;
while (n < a.size() + b.size())
n <<= 1;
fa.resize(n);
fb.resize(n);
fft(fa, false);
fft(fb, false);
for (int i = 0; i < n; i++)
fa[i] *= fb[i];
fft(fa, true);
vector<int> result(n);
for (int i = 0; i < n; i++)
result[i] = round(fa[i].real());
int carry = 0;
for (int i = 0; i < n; i++){
result[i] += carry;
carry = result[i] / 10;
result[i] %= 10;
}
return result;
}
vector<int> subtractStrings(vector<int> &a, vector<int> &b) {
vector<int> result;
int borrow = 0;
int i = (int)a.size() - 1;
int j = (int)b.size() - 1;
while (i >= 0) {
int diff = a[i--] - borrow;
if (j >= 0) diff -= b[j--];
if (diff < 0) {
diff += 10;
borrow = 1;
} else {
borrow = 0;
}
result.push_back(diff);
}
// Remove leading zeros from the result
while (result.size() > 1 && result.back() == '0') {
result.pop_back();
}
reverse(result.begin(), result.end());
return result;
}
int main() {
if(strcmp(__FILE__,"tempCodeRunnerFile.cpp")==0) freopen("input.txt","r",stdin);
int tc=1;
scanf("%d",&tc);
while(tc--){
int x, n;
scanf("%d %d",&x,&n);
int denominator = x - 1;
vector<int> numerator={1},one={1},X;
while(x){
X.push_back(x%10);
x/=10;
}
while(X.size()<1024) X.push_back(0);
while(numerator.size()<1024) numerator.push_back(0);
// binary exponentiation
while(n){
if(n&1) numerator=multiply(X,numerator);
X=multiply(X,X);
n/=2;
}
// removing leading zeroes
while(!numerator.empty()){
if(numerator.back()==0) numerator.pop_back();
else break;
}
reverse(numerator.begin(),numerator.end());
numerator=subtractStrings(numerator,one);
for(int val:numerator){
printf("%d",val);
}
printf("/%d\n",denominator);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnVzaW5nIGNkID0gY29tcGxleDxkb3VibGU+Owpjb25zdCBkb3VibGUgUEkgPSBhY29zKC0xKTsKCnZvaWQgZmZ0KHZlY3RvcjxjZD4gJiBhLCBib29sIGludmVydCkgewogICAgaW50IG4gPSBhLnNpemUoKTsKICAgIGlmIChuID09IDEpCiAgICAgICAgcmV0dXJuOwoKICAgIHZlY3RvcjxjZD4gYTAobiAvIDIpLCBhMShuIC8gMik7CiAgICBmb3IgKGludCBpID0gMDsgMiAqIGkgPCBuOyBpKyspIHsKICAgICAgICBhMFtpXSA9IGFbMippXTsKICAgICAgICBhMVtpXSA9IGFbMippKzFdOwogICAgfQogICAgZmZ0KGEwLCBpbnZlcnQpOwogICAgZmZ0KGExLCBpbnZlcnQpOwoKICAgIGRvdWJsZSBhbmcgPSAyICogUEkgLyBuICogKGludmVydCA/IC0xIDogMSk7CiAgICBjZCB3KDEpLCB3bihjb3MoYW5nKSwgc2luKGFuZykpOwogICAgZm9yIChpbnQgaSA9IDA7IDIgKiBpIDwgbjsgaSsrKSB7CiAgICAgICAgYVtpXSA9IGEwW2ldICsgdyAqIGExW2ldOwogICAgICAgIGFbaSArIG4vMl0gPSBhMFtpXSAtIHcgKiBhMVtpXTsKICAgICAgICBpZiAoaW52ZXJ0KSB7CiAgICAgICAgICAgIGFbaV0gLz0gMjsKICAgICAgICAgICAgYVtpICsgbi8yXSAvPSAyOwogICAgICAgIH0KICAgICAgICB3ICo9IHduOwogICAgfQp9Cgp2ZWN0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AtIGJvcnJvdzsKICAgICAgICBpZiAoaiA+PSAwKSBkaWZmIC09IGJbai0tXTsKICAgICAgICBpZiAoZGlmZiA8IDApIHsKICAgICAgICAgICAgZGlmZiArPSAxMDsKICAgICAgICAgICAgYm9ycm93ID0gMTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBib3Jyb3cgPSAwOwogICAgICAgIH0KICAgICAgICByZXN1bHQucHVzaF9iYWNrKGRpZmYpOwogICAgfQogICAgLy8gUmVtb3ZlIGxlYWRpbmcgemVyb3MgZnJvbSB0aGUgcmVzdWx0CiAgICB3aGlsZSAocmVzdWx0LnNpemUoKSA+IDEgJiYgcmVzdWx0LmJhY2soKSA9PSAnMCcpIHsKICAgICAgICByZXN1bHQucG9wX2JhY2soKTsKICAgIH0KICAgIHJldmVyc2UocmVzdWx0LmJlZ2luKCksIHJlc3VsdC5lbmQoKSk7CiAgICByZXR1cm4gcmVzdWx0Owp9CiAKaW50IG1haW4oKSB7CiAgICBpZihzdHJjbXAoX19GSUxFX18sInRlbXBDb2RlUnVubmVyRmlsZS5jcHAiKT09MCkgZnJlb3BlbigiaW5wdXQudHh0IiwiciIsc3RkaW4pOwogICAgaW50IHRjPTE7CiAgICBzY2FuZigiJWQiLCZ0Yyk7CiAgICB3aGlsZSh0Yy0tKXsKICAgICAgICBpbnQgeCwgbjsKICAgICAgICBzY2FuZigiJWQgJWQiLCZ4LCZuKTsKICAgICAgICBpbnQgZGVub21pbmF0b3IgPSB4IC0gMTsKICAgICAgICB2ZWN0b3I8aW50PiBudW1lcmF0b3I9ezF9LG9uZT17MX0sWDsKICAgICAgICB3aGlsZSh4KXsKICAgICAgICAgICAgWC5wdXNoX2JhY2soeCUxMCk7CiAgICAgICAgICAgIHgvPTEwOwogICAgICAgIH0gICAgICAgIAogICAgICAgIHdoaWxlKFguc2l6ZSgpPDEwMjQpIFgucHVzaF9iYWNrKDApOwogICAgICAgIHdoaWxlKG51bWVyYXRvci5zaXplKCk8MTAyNCkgbnVtZXJhdG9yLnB1c2hfYmFjaygwKTsKICAgICAgICAvLyBiaW5hcnkgZXhwb25lbnRpYXRpb24KICAgICAgICB3aGlsZShuKXsKICAgICAgICAgICAgaWYobiYxKSBudW1lcmF0b3I9bXVsdGlwbHkoWCxudW1lcmF0b3IpOwogICAgICAgICAgICBYPW11bHRpcGx5KFgsWCk7CiAgICAgICAgICAgIG4vPTI7CiAgICAgICAgfQogICAgICAgIC8vIHJlbW92aW5nIGxlYWRpbmcgemVyb2VzCiAgICAgICAgd2hpbGUoIW51bWVyYXRvci5lbXB0eSgpKXsKICAgICAgICAgICAgaWYobnVtZXJhdG9yLmJhY2soKT09MCkgbnVtZXJhdG9yLnBvcF9iYWNrKCk7CiAgICAgICAgICAgIGVsc2UgYnJlYWs7CiAgICAgICAgfQogICAgICAgIHJldmVyc2UobnVtZXJhdG9yLmJlZ2luKCksbnVtZXJhdG9yLmVuZCgpKTsKICAgICAgICAKICAgICAgICBudW1lcmF0b3I9c3VidHJhY3RTdHJpbmdzKG51bWVyYXRvcixvbmUpOwogICAgICAgIGZvcihpbnQgdmFsOm51bWVyYXRvcil7CiAgICAgICAgICAgIHByaW50ZigiJWQiLHZhbCk7CiAgICAgICAgfQogICAgICAgIHByaW50ZigiLyVkXG4iLGRlbm9taW5hdG9yKTsKICAgIH0KICAgIHJldHVybiAwOwp9CiA=