???????????? ????????????,?????????:)
????????????
?????????????????????
????????????
?????????????????????
???????????????maxdep
???dfs??????????????????????????????????????????
???????????????????????????????????????
?????????????????????k?????????1/k<=??????/??????
?????????max(k,last+1)???????????????
->??????????????????????????????????????????????????????????????????????????????????????????
???????????????k.
??????????????????????????????????????????
????????????
/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
/*
???????????????????????????????????????!!!
*/
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e3;
bool bo[N+10];
int a,b,k,maxdep;
vector<ll> v,ans;
ll getidx(int a,int b){
//1/i <= a/b ??? i??????
//b<=a*i
ll l= 1,r = 1e8;
ll temp = -1;
while (l <= r){
int m = (l+r)>>1;
if (1LL*a*m>=b){
temp = m;
r = m - 1;
}else l = m + 1;
}
return temp;
}
bool Greater(vector<ll> v,vector <ll> ans){
if ((int)ans.size()==0) return true;
for (int i = (int)v.size()-1;i>=0;i--)
if (v[i]!=ans[i]){
if (v[i]>ans[i]) return false;else return true;
}
return false;
}
bool dfs(int dep,int a,int b,ll last){
if (dep==maxdep){
if (a==1 && b>last){
if (b<=1000 && bo[b]) return false;
v.push_back(b);
if (Greater(v,ans)) ans = v;
v.pop_back();
return true;
}
return false;
}
ll idx = getidx(a,b);
ll ma = max(last+1,idx);
ll delta = maxdep-dep+1;
//delta/ma<a/b
bool ok = false;
for (ll i = ma; ;i++)
{
if (i<=1000 && bo[i]) continue;
if (delta*b<a*i) break;
//a/b - 1/i
v.push_back(i);
ll fenzi = a*i-b,fenmu = b*i;
ll temp = __gcd(fenzi,fenmu);
fenzi/=temp,fenmu/=temp;
if (dfs(dep+1,fenzi,fenmu,i)) ok = true;
v.pop_back();
}
return ok;
}
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int T;
cin >> T;
int kase = 0;
while(T--){
memset(bo,0,sizeof bo);
cin >> a >> b >> k;
while (k--){
int x;
cin >> x;
bo[x] = 1;
}
ans.clear();
v.clear();
for (maxdep = 1;;maxdep++){
if (dfs(1,a,b,1)){
cout <<"Case "<<++kase<<": "<<a<<"/"<<b<<"=1/"<<ans[0];
for (int i = 1;i <(int) ans.size();i++)
cout << "+1/"<<ans[i];
break;
}
}
cout << endl;
}
return 0;
}