#include <iostream>
using namespace std;

long gcd(long n, long m)
{
	if (m==0)
		return n;
	else
		return gcd(m, n%m);
}

class rat
{
public:
	long num, den;
	rat() {
		num = 0;
		den = 1;
	};
	rat(long n, long d) {
		bool pos = true;
		if (d<0) {
			d=-d;
			pos = !pos;
		}
		if (n<0) {
			n = -n;
			pos = !pos;
		}
		long fac = gcd(n, d);
		num = n/fac;
		den = d/fac;
		if (!pos) num = -num;
	};
	rat add(rat rhs) {
		long newNum = num*rhs.den + den*rhs.num;
		long newDen = den*rhs.den;
		rat ans(newNum, newDen);
		return ans;
	};
	rat sub(rat rhs) {
		long newNum = num*rhs.den - den*rhs.num;
		long newDen = den*rhs.den;
		rat ans(newNum, newDen);
		return ans;
	};
	rat mul(rat rhs) {
		long newNum = num*rhs.num;
		long newDen = den*rhs.den;
		rat ans(newNum, newDen);
		return ans;
	};
	rat div(rat rhs) {
		long newNum = num*rhs.den;
		long newDen = den*rhs.num;
		rat ans(newNum, newDen);
		return ans;
	};
	void print() {
		if (num == 0)
			cout << '0';
		else if (den == 1)
			cout << num;
		else
			cout <<  num << '/' << den;
	}
};

rat operator+(rat a, rat b) { return a.add(b); };
rat operator-(rat a, rat b) { return a.sub(b); };
rat operator*(rat a, rat b) { return a.mul(b); };
rat operator/(rat a, rat b) { return a.div(b); };
ostream& operator<<(ostream &out, rat a) {a.print(); return out;};

const int MAXD = 10;

rat q[MAXD], p[MAXD], f[MAXD], a[MAXD][MAXD], b[MAXD];

void printarray(rat a[MAXD][MAXD], int n)			// debug routine
{
	for(int i=0; i<n; i++) {
		for(int j=0; j<n; j++)
			cout << a[i][j] << ' ';
		cout << endl;
	}
}

void solve (rat a[MAXD][MAXD], rat b[MAXD], rat q[MAXD], int n)
//
// gauss elimination
//
{
int i;
	for(i=0; i<n; i++)
		q[i] = b[i];
	for(i=0; i<n-1; i++) {
		int j=i;
		while (a[i][j].num == 0)			// select pivot
			j++;
		if (j != i) {
			rat temp = b[j];
			b[j] = b[i];
			b[i] = temp;
			for(int k=0; k<n; k++) {
				temp = a[j][k];
				a[j][k] = a[i][k];
				a[i][k] = temp;
			}
		}
		for(int k=i+1; k<n; k++) {		// eliminate row k
			rat fact;
			fact = a[k][i]/a[i][i];
			for(int l=i; l<n; l++) {
				a[k][l] = a[k][l] - a[i][l]*fact;
			}
			b[k] = b[k] - b[i]*fact;
		}
	}
	q[n-1] = b[n-1]/a[n-1][n-1];			// back substitution
	for(i=n-2; i>=0; i--) {
		q[i] = b[i];
		for(int j=i+1; j<n; j++)
			q[i] = q[i] - a[i][j]*q[j];
		q[i] = q[i]/a[i][i];
	}
}

void printPoly(rat p[], int n)
{
	int i=0;
	while (i<n && p[i].num == 0)
		i++;
	if (i == n)
		cout << "(0,0)" << endl;
	else {
		cout << '(' << p[i] << ',' << i << ')';
		i++;
		for(; i<n; i++) {
			if (p[i].num != 0)
				cout << " (" << p[i] << ',' << i << ')';
		}
		cout << endl;
	}
}

int main()
{
	int m, n;
	cin >> m >> n;
	int ncase = 0;
	while (m != 0) {
		ncase++;
int i;
		for(i=0; i<m+n; i++) {
			cin >> f[i].num;
			f[i].den = 1;
		}
		for(i=0; i<n; i++) {  			// build linear system for q coeffs
			for(int j=0; j<n; j++) {
				if (m+j-i >= 0)
					a[i][n-j-1] = f[m+j-i];
				else {
					a[i][n-j-1].num = 0;
					a[i][n-j-1].den = 1;
				}
			}
			b[i].num = (i==0) ? 1 : 0;
			b[i].den = 1;
		}
		solve(a, b, q, n);

		for(i=m-1; i>=0; i--) {			// solve for p coeffs
			p[i] = q[0]*f[i];
			for(int j=1; j<n; j++) {
				if (i-j >= 0)
					p[i] = p[i] + q[j]*f[i-j];
			}
		}
		printPoly(p, m);
		printPoly(q, n);
		cin >> m >> n;
		if (m != 0)
			cout << endl;
	}
	return 0;
}
