#include <fstream>
#include <iostream>
using namespace std;
int f[1000][1001];
int viz[1000];
int GCD(int a, int b) {
int r = a % b;
while(r) {
a = b;
b = r;
r = a % b;
}
return b;
}
int main()
{
ifstream cin("frac.in");
//ofstream cout("frac.out");
int m, n, nr = 0, nrf = 0;
cin >> n;
while(!cin.eof()) {
cin >> m;
++nr;
int nc = n;
for(int i = 1; i < 1000; ++i)
viz[i] = 0;
viz[0] = 1;
while(!viz[nc % m]){
viz[nc % m] = 1;
nc = (nc % m) * 10;
}
nc = nc % m;
int cm = GCD(nc, m);
++f[nc / cm][m / cm];
cout << n / m;
cout << ',';
if(n % m == 0) {
cout << 0 << '\n';
cin >> n;
continue;
}
while(n % m != nc) {
n = (n % m) * 10;
cout << n / m;
}
if(nc > 0) {
cout << '(';
n = (n % m) * 10;
cout << n / m;
while(n % m != nc) {
n = (n % m) * 10;
cout << n / m;
}
cout << ')';
}
cout << '\n';
cin >> n;
}
int ifin = 0, jfin = 0;
for(int i = 1; i < 1000; ++i)
for(int j = 1; j <= 1000; ++j)
if(f[i][j] > nrf) {
nrf = f[i][j];
ifin = i;
jfin = j;
}
if(nrf > nr / 2) {
int ic = ifin, jc = jfin, r = ic % jc;
ic = (ic % jc) * 10;
cout << ic / jc;
while(ic % jc != r) {
ic = (ic % jc) * 10;
cout << ic / jc;
}
}
else
cout << -1;
return 0;
}