#include<bits/stdc++.h>

using namespace std;

int T;
int p,q;

inline string work(int x,int y)
{
    if(x%y == 0) return to_string(x/y);
    int tmp = x/y;
    x %= y;
    if(y%x == 0) return to_string(tmp) + "+1/" + work(y,x);
    else return to_string(tmp) + "+1/" + "{" + work(y,x) +"}";
}

inline void solve()
{
    cin>>p>>q;
    cout<<p<<'/'<<q<<" = "<<work(p,q)<<'\n';
}

int main()
{
    cin>>T;
    while(T--) solve();
    return 0;
}