#include<bits/stdc++.h>
using namespace std;
const int N = 20;
long long GCD(long long a, long long b) { return (b == 0) ? a : GCD(b, a % b); }
inline long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
inline long long normalize(long long x, long long mod) { x %= mod; if (x < 0) x += mod; return x; }
struct GCD_type { long long x, y, d; };
GCD_type ex_GCD(long long a, long long b)
{
if (b == 0) return {1, 0, a};
GCD_type pom = ex_GCD(b, a % b);
return {pom.y, pom.x - a / b * pom.y, pom.d};
}
int testCases;
int t;
long long a[N], n[N], ans, lcm;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> t;
for(int i = 1; i <= t; i++) cin >> a[i] >> n[i], normalize(a[i], n[i]);
ans = a[1];
lcm = n[1];
for(int i = 2; i <= t; i++)
{
auto pom = ex_GCD(lcm, n[i]);
int x1 = pom.x;
int d = pom.d;
if((a[i] - ans) % d != 0) return cerr << "No solutions" << endl, 0;
ans = normalize(ans + x1 * (a[i] - ans) / d % (n[i] / d) * lcm, lcm * n[i] / d);
lcm = LCM(lcm, n[i]); // you can save time by replacing above lcm * n[i] /d by lcm = lcm * n[i] / d
}
cout << ans << " " << lcm << endl;
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY29uc3QgaW50IE4gPSAyMDsKbG9uZyBsb25nIEdDRChsb25nIGxvbmcgYSwgbG9uZyBsb25nIGIpIHsgcmV0dXJuIChiID09IDApID8gYSA6IEdDRChiLCBhICUgYik7IH0KaW5saW5lIGxvbmcgbG9uZyBMQ00obG9uZyBsb25nIGEsIGxvbmcgbG9uZyBiKSB7IHJldHVybiBhIC8gR0NEKGEsIGIpICogYjsgfQppbmxpbmUgbG9uZyBsb25nIG5vcm1hbGl6ZShsb25nIGxvbmcgeCwgbG9uZyBsb25nIG1vZCkgeyB4ICU9IG1vZDsgaWYgKHggPCAwKSB4ICs9IG1vZDsgcmV0dXJuIHg7IH0Kc3RydWN0IEdDRF90eXBlIHsgbG9uZyBsb25nIHgsIHksIGQ7IH07CkdDRF90eXBlIGV4X0dDRChsb25nIGxvbmcgYSwgbG9uZyBsb25nIGIpCnsKICAgIGlmIChiID09IDApIHJldHVybiB7MSwgMCwgYX07CiAgICBHQ0RfdHlwZSBwb20gPSBleF9HQ0QoYiwgYSAlIGIpOwogICAgcmV0dXJuIHtwb20ueSwgcG9tLnggLSBhIC8gYiAqIHBvbS55LCBwb20uZH07Cn0KaW50IHRlc3RDYXNlczsKaW50IHQ7CmxvbmcgbG9uZyBhW05dLCBuW05dLCBhbnMsIGxjbTsKaW50IG1haW4oKQp7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOwogICAgY2luLnRpZSgwKTsKICAgIGNpbiA+PiB0OwogICAgZm9yKGludCBpID0gMTsgaSA8PSB0OyBpKyspIGNpbiA+PiBhW2ldID4+IG5baV0sIG5vcm1hbGl6ZShhW2ldLCBuW2ldKTsKICAgIGFucyA9IGFbMV07CiAgICBsY20gPSBuWzFdOwogICAgZm9yKGludCBpID0gMjsgaSA8PSB0OyBpKyspCiAgICB7CiAgICAgICAgYXV0byBwb20gPSBleF9HQ0QobGNtLCBuW2ldKTsKICAgICAgICBpbnQgeDEgPSBwb20ueDsKICAgICAgICBpbnQgZCA9IHBvbS5kOwogICAgICAgIGlmKChhW2ldIC0gYW5zKSAlIGQgIT0gMCkgcmV0dXJuIGNlcnIgPDwgIk5vIHNvbHV0aW9ucyIgPDwgZW5kbCwgMDsKICAgICAgICBhbnMgPSBub3JtYWxpemUoYW5zICsgeDEgKiAoYVtpXSAtIGFucykgLyBkICUgKG5baV0gLyBkKSAqIGxjbSwgbGNtICogbltpXSAvIGQpOwogICAgICAgIGxjbSA9IExDTShsY20sIG5baV0pOyAvLyB5b3UgY2FuIHNhdmUgdGltZSBieSByZXBsYWNpbmcgYWJvdmUgbGNtICogbltpXSAvZCBieSBsY20gPSBsY20gKiBuW2ldIC8gZAogICAgfQogICAgY291dCA8PCBhbnMgPDwgIiAiIDw8IGxjbSA8PCBlbmRsOwoKICAgIHJldHVybiAwOwp9Cg==