#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <assert.h>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

typedef vector<ll> Array;
typedef vector<Array> Matrix;

ostream& operator<<(ostream &os, const Array &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
ostream& operator<<(ostream &os, const Matrix &t) {
FOR(it,t)os<<*it<<endl;return os;
}

int n;

ll readnumber(string &s, int &p){
	ll res = 0;
	while(isdigit(s[p])){
		res = res*10 + s[p++] - '0';
	}
	return res;
}

void readmol(string &s, int &p, map<string, ll> &res);

map<string, ll> readunitgroup(string &s, int &p){
	map<string, ll> res;
//	cout << p << ", " << s[p] << endl;
	if(s[p] == '('){
		p ++;
		readmol(s, p, res);
		p ++;
	}else if(isupper(s[p])){
		string t = "";
		t.push_back(s[p++]);
		if(islower(s[p])) t.push_back(s[p++]);
		res[t] ++;
	}else assert(false);
	return res;
}

void readmol(string &s, int &p, map<string, ll> &res){
	map<string, ll> left, right;
	while(1){
		auto ret = readunitgroup(s, p);
		ll times = 1;
		if(isdigit(s[p])) times = readnumber(s, p);
		FOR(it, ret) res[it->first] += it->second*times;
		if(!isupper(s[p]) && s[p] != '(') break;
	}
}

void jordan(Matrix &M){
	int N = M.size();
	int W = M[0].size();
	int ret = 0;
	int j = 0;
	for(int i=0;i<N;j++){
		int ma=i;
		for(int k=i;k<N;k++) if(abs(M[ma][j]) < abs(M[k][j])) ma = k;
		swap(M[i], M[ma]);
		if(!M[i][j]) continue;
		for(;!M[i][j]&&j<W;j++);
		if(W<=j) break;
		for(int k=0;k<N;k++)if(k!=i && M[k][j]){
			ll p = M[i][j];
			ll q = M[k][j];
			ll g = __gcd(p, q);
			p /= g;
			q /= g;
			for(int l=0;l<W;l++) M[k][l] = M[k][l]*p - M[i][l]*q;
		}
		ret ++;
		i ++;
	}
}

inline ll lcm(ll a, ll b){
	return a/__gcd(a, b)*b;
}

void solve(string s){
	vector<map<string, ll>> mols;
	vector<string> strs;
	int p=0;
	while(1){
		mols.emplace_back();
		readmol(s, p, mols.back());
		FOR(it, mols.back()){
			strs.push_back(it->first);
		}
		if(s[p] != '+') break;
		p ++;
	}
	p += 2;
	while(1){
		mols.emplace_back();
		readmol(s, p, mols.back());
		FOR(it, mols.back()){
			strs.push_back(it->first);
			it->second *= -1;
		}
		if(s[p] != '+') break;
		p ++;
	}
	p ++;

	sort(ALL(strs));UNIQUE(strs);
	Matrix m(strs.size(), Array(mols.size()));
	REP(i, mols.size()){
		FOR(it, mols[i]){
			int t = lower_bound(ALL(strs), it->first) - strs.begin();
			m[t][i] = it->second;
		}
	}
	jordan(m);
	int w = mols.size() - 1;
	ll l = 1;
	REP(i, w) l = lcm(l, abs(m[i][i])/__gcd(abs(m[i][i]), abs(m[i][w])));
	REP(i, w){
		cout << -m[i][w]*l/m[i][i] << " ";
	}
	cout << l << endl;
}

main(){
	ios::sync_with_stdio(false);
	string s;
	while(cin >> s, s != "."){
		solve(s);
	}
	return 0;
}

Measured memory_bytes: 1252