#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
#define PI atan2(0, -1)
#define epsilon 1e-9
#define INF 5e18
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
int kase, N;
pair<long long, long long> arr [15], mini, maxi, ret;
bool ok;
long long lo, hi;
void updateMini(pair<long long, long long> a){
if(mini.f == -1){
mini = a;
return;
}
if(a.f*mini.s > a.s*mini.f) mini = a;
}
void updateMaxi(pair<long long, long long> a){
if(maxi.f == -1){
maxi = a;
return;
}
if(a.f*maxi.s < a.s*maxi.f) maxi = a;
}
int main(){
//freopen("sort.in", "r", stdin); freopen("sort.out", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
cin >> kase;
for(int kk = 1; kk <= kase; kk++){
cin >> N; assert(N <= 10); mini = mp(-1, -1); maxi = mp(-1, -1); ok = true;
for(int i = 0; i < N; i++) cin >> arr[i].f >> arr[i].s;
for(int i = 0; i < N && ok; i++)
for(int j = i+1; j < N; j++){
if(arr[j].f >= arr[i].f && arr[j].s >= arr[i].s) continue;
if(arr[j].f <= arr[i].f && arr[j].s <= arr[i].s){ ok = false; break; }
long long uno = arr[j].f-arr[i].f, dos = arr[i].s-arr[j].s;
long long gg = __gcd(abs(uno), abs(dos)); uno /= gg; dos /= gg;
if(dos > 0) updateMaxi(mp(uno, dos));
else updateMini(mp(-uno, -dos));
}
if(!ok){
cout << "Case #" << kk << ": IMPOSSIBLE\n";
continue;
}
if(mini.f == -1) mini = mp(1, 2*MOD);
if(maxi.f == -1) maxi = mp(2*MOD, 1);
if(mini.f*maxi.s >= mini.s*maxi.f){
cout << "Case #" << kk << ": IMPOSSIBLE\n";
continue;
}
lo = 1; hi = 2*(mini.s+maxi.s); ret = mp(-1, -1);
while(lo <= hi){
long long mid = (lo+hi)/2;
long long lefty = (mini.f*mid)/mini.s+1;
long long righty = (maxi.f*mid)/maxi.s;
if((maxi.f*mid)%maxi.s == 0) righty--;
if(lefty <= righty){
hi = mid-1;
ret = mp(mid, lefty);
}
else lo = mid+1;
}
assert(ret != mp(-1ll, -1ll));
cout << "Case #" << kk << ": " << ret.f << ' ' << ret.s << '\n';
}
return 0;
}
/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/
I2RlZmluZSBfX1VTRV9NSU5HV19BTlNJX1NURElPIDAKI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgojaW5jbHVkZSA8ZXh0L3BiX2RzL2Fzc29jX2NvbnRhaW5lci5ocHA+CiNpbmNsdWRlIDxleHQvcGJfZHMvdHJlZV9wb2xpY3kuaHBwPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdGVtcGxhdGUgPGNsYXNzIFQ+CnVzaW5nIG9yZGVyZWRfc2V0ID0gX19nbnVfcGJkczo6dHJlZTxULCBfX2dudV9wYmRzOjpudWxsX3R5cGUsIGxlc3M8VD4sIF9fZ251X3BiZHM6OnJiX3RyZWVfdGFnLCBfX2dudV9wYmRzOjp0cmVlX29yZGVyX3N0YXRpc3RpY3Nfbm9kZV91cGRhdGU+Owp0ZW1wbGF0ZSA8Y2xhc3MgVD4KdXNpbmcgb3JkZXJlZF9tdWx0aXNldCA9IF9fZ251X3BiZHM6OnRyZWU8VCwgX19nbnVfcGJkczo6bnVsbF90eXBlLCBsZXNzX2VxdWFsPFQ+LCBfX2dudV9wYmRzOjpyYl90cmVlX3RhZywgX19nbnVfcGJkczo6dHJlZV9vcmRlcl9zdGF0aXN0aWN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9yKGludCBrayA9IDE7IGtrIDw9IGthc2U7IGtrKyspewogICAgICAgIGNpbiA+PiBOOyBhc3NlcnQoTiA8PSAxMCk7IG1pbmkgPSBtcCgtMSwgLTEpOyBtYXhpID0gbXAoLTEsIC0xKTsgb2sgPSB0cnVlOwogICAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCBOOyBpKyspIGNpbiA+PiBhcnJbaV0uZiA+PiBhcnJbaV0uczsKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgTiAmJiBvazsgaSsrKQogICAgICAgICAgICBmb3IoaW50IGogPSBpKzE7IGogPCBOOyBqKyspewogICAgICAgICAgICAgICAgaWYoYXJyW2pdLmYgPj0gYXJyW2ldLmYgJiYgYXJyW2pdLnMgPj0gYXJyW2ldLnMpIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgaWYoYXJyW2pdLmYgPD0gYXJyW2ldLmYgJiYgYXJyW2pdLnMgPD0gYXJyW2ldLnMpeyBvayA9IGZhbHNlOyBicmVhazsgfQogICAgICAgICAgICAgICAgbG9uZyBsb25nIHVubyA9IGFycltqXS5mLWFycltpXS5mLCBkb3MgPSBhcnJbaV0ucy1hcnJbal0uczsKICAgICAgICAgICAgICAgIGxvbmcgbG9uZyBnZyA9IF9fZ2NkKGFicyh1bm8pLCBhYnMoZG9zKSk7IHVubyAvPSBnZzsgZG9zIC89IGdnOwogICAgICAgICAgICAgICAgaWYoZG9zID4gMCkgdXBkYXRlTWF4aShtcCh1bm8sIGRvcykpOwogICAgICAgICAgICAgICAgZWxzZSB1cGRhdGVNaW5pKG1wKC11bm8sIC1kb3MpKTsKICAgICAgICAgICAgfQogICAgICAgIGlmKCFvayl7CiAgICAgICAgICAgIGNvdXQgPDwgIkNhc2UgIyIgPDwga2sgPDwgIjogSU1QT1NTSUJMRVxuIjsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIGlmKG1pbmkuZiA9PSAtMSkgbWluaSA9IG1wKDEsIDIqTU9EKTsKICAgICAgICBpZihtYXhpLmYgPT0gLTEpIG1heGkgPSBtcCgyKk1PRCwgMSk7CiAgICAgICAgaWYobWluaS5mKm1heGkucyA+PSBtaW5pLnMqbWF4aS5mKXsKICAgICAgICAgICAgY291dCA8PCAiQ2FzZSAjIiA8PCBrayA8PCAiOiBJTVBPU1NJQkxFXG4iOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CiAgICAgICAgbG8gPSAxOyBoaSA9IDIqKG1pbmkucyttYXhpLnMpOyByZXQgPSBtcCgtMSwgLTEpOwogICAgICAgIHdoaWxlKGxvIDw9IGhpKXsKICAgICAgICAgICAgbG9uZyBsb25nIG1pZCA9IChsbytoaSkvMjsKICAgICAgICAgICAgbG9uZyBsb25nIGxlZnR5ID0gKG1pbmkuZiptaWQpL21pbmkucysxOwogICAgICAgICAgICBsb25nIGxvbmcgcmlnaHR5ID0gKG1heGkuZiptaWQpL21heGkuczsKICAgICAgICAgICAgaWYoKG1heGkuZiptaWQpJW1heGkucyA9PSAwKSByaWdodHktLTsKICAgICAgICAgICAgaWYobGVmdHkgPD0gcmlnaHR5KXsKICAgICAgICAgICAgICAgIGhpID0gbWlkLTE7CiAgICAgICAgICAgICAgICByZXQgPSBtcChtaWQsIGxlZnR5KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIGxvID0gbWlkKzE7CiAgICAgICAgfQogICAgICAgIGFzc2VydChyZXQgIT0gbXAoLTFsbCwgLTFsbCkpOwogICAgICAgIGNvdXQgPDwgIkNhc2UgIyIgPDwga2sgPDwgIjogIiA8PCByZXQuZiA8PCAnICcgPDwgcmV0LnMgPDwgJ1xuJzsKICAgIH0KICAgIHJldHVybiAwOwp9CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCkthdGViYSBpaSBkYWtlIG5vIGhhbmFzaGkgZGFyb3UKU3VjY2VzcyBpcyBvbmx5IGEgdmljdG9yeSBhd2F5Ci0gTm8gR2FtZSBObyBMaWZlIE9wZW5pbmcKKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwo=