#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <utility>
#include <string>
#include <cctype>
#include <cstdlib>
#include <algorithm>
using namespace std;

typedef long long LL;

LL gcd(LL a, LL b){
	while(b){
		LL r = a % b;
		a = b;
		b = r;
	}
	return a;
}

struct frac{
	LL num, den;

	frac(LL n, LL d = 1LL) : num(n), den(d){
		LL g = gcd(num, den);
		num /= g;
		den /= g;
	}

	frac operator +(const frac &f) const{
		return frac(f.den * num + f.num * den , den * f.den);
	}

	frac operator -(const frac &f) const{
		return frac(num * f.den - f.num * den, den * f.den);
	}

	frac operator *(const frac &f) const{
		return frac(num * f.num, den * f.den);
	}
	
	frac operator /(const frac &f) const{
		return frac(num * f.den, den * f.num);
	}
};


char name[4];
const char *ptr;
map<string,int> tbl;

vector<int> parse(){
	vector<int> ret(tbl.size());

	while(true){
		if( *ptr == '(' ){
			++ptr;
			vector<int> r = parse();
			++ptr;
			
			int x = 1;
			if( isdigit(*ptr) ){
				char *endp;
				x = strtol(ptr, &endp, 10);
				ptr = endp;
			}
			
			for(int i = 0; i < tbl.size(); ++i){
				ret[i] += r[i] * x;
			}
		}
		else if( isupper(*ptr) ){
			name[0] = *ptr++;
			name[1] = 0;
			
			if( islower(*ptr) ){
				name[1] = *ptr++;
			}

			int y = tbl[name];
			int x = 1;

			if( isdigit(*ptr) ){
				char *endp;
				x = strtol(ptr, &endp, 10);
				ptr = endp;
			}
			
			ret[y] += x;
		}
		else{
			break;
		}
	}
	return ret;
}


int main(){
	string expr;
	while( cin >> expr, expr[0] != '.' ){
		tbl.clear();

		int dim = 1;

		for( ptr = expr.c_str(); *ptr != '.'; ){
			if( *ptr == '+' || *ptr == '-' ){
				++dim;
			}

			if( isupper(*ptr) ){
				name[0] = *ptr++;
				name[1] = 0;
				
				if( islower(*ptr) ){
					name[1] = *ptr++;
				}

				tbl.insert( make_pair(name, tbl.size()) );
			}
			else{
				++ptr;
			}
		}

		int n = tbl.size();
		vector<vector<frac> > a(n + 1, vector<frac>(dim + 1, 0));

		a[n][0] = a[n][dim] = 1;

		bool minus = false;
		ptr = expr.c_str();
		for(int u = 0; u < dim; ++u){
			vector<int> res = parse();
			for(int i = 0; i < n; ++i){
				if( minus ){
					a[i][u] = -res[i];
				}
				else{
					a[i][u] = res[i];
				}
			}

			if( *ptr == '-' ){
				ptr += 2;
				minus = true;
			}
			else{
				++ptr;
			}

		}
		swap(a[0], a[n]);

		for(int i = 0; i < min(dim, n+1); ++i){
			int index;
			for(index = i; index <= n && a[index][i].num == 0; ++index);
			if( index > n ) continue;
			a[i].swap(a[index]);

			frac piv = a[i][i];
			for(int j = i; j <= dim; ++j){
				a[i][j] = a[i][j] / piv;
			}

			for(int j = 0; j <= n; ++j){
				if(i == j){	continue;	}
				frac t = a[j][i];

				for(int k = 0; k <= dim; ++k){
					a[j][k] = a[j][k] - t * a[i][k];
				}
			}
		}

		LL lcm = 1;
		for(int i = 0; i <= n; ++i){
			lcm *= a[i][dim].den / gcd(lcm, a[i][dim].den);
		}

		for(int i = 0; i < dim; ++i){
			LL z = lcm / a[i][dim].den * a[i][dim].num;
			if( i != 0 ){	cout << ' ';	}
			cout << z;
		}
		cout << endl;
	}
}