#include <bits/stdc++.h>
using namespace std;
using vs=vector<string>;
using vvs=vector<vs>;
using D=map<string,int>;
using vi=vector<int>;
using vvi=vector<vi>;

vector<D> data;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
constexpr int lcm(int a, int b){return a>=b?a%b==0?b:lcm(b,a%b):lcm(b,a);}
constexpr int gcd(int a, int b){return a*b/lcm(a,b);}

void analyze(string s,int index, int x);

void add(D &m, string s,int v, int index){
    if(s.back()==')'){
        analyze(s.substr(0,s.size()-1)+".",index,v);
    }else if(index!=-1){
        add(data[index],s,v,-1);
    }else{
        if(m.find(s)==m.end())
            m[s]=v;
        else
            m[s]+=v;
    }
}

void analyze(string s, int index=-1, int x=1){
    string name="",value="",def="";
    if(index==-1){
        data.push_back(D());
    }
    for(auto c:s){
        if(c=='>'){
            name="", def="-";
        }else if(name[0]=='('){
            name+=c;
            if(c==')')
                name=name.substr(1);
        }else if(isupper(c) || c=='-' || c=='+' || c=='.' || c=='('){
            if(name!=""){
                if(value=="") value="1";
                add(data.back(),name,stoi(def+value)*x,index);
                index=-1;
            }
            if(c=='('){
                index=data.size()-1;
                name=c;
                value="";
                continue;
            }
            switch(c){
                case '+': case '-':
                    data.push_back(D());
                    name="";break;
                case '.': return;
                default: name=c;
            }
            value="";
        }else if(islower(c)){
            name+=c;
        }else{
            value+=c;
        }
    }
}

int main(void){
    string s;
    while(cin>>s,s!="."){
        data.clear();
        analyze(s);
        vs chem;
        for(auto d : data){
            for(auto p:d){
                if(find(all(chem),p.first)==chem.end()){
                    chem.push_back(p.first);
                }
            }
        }

        vvi mat(chem.size(),vi(data.size(),0));
        rep(i,data.size()){
            //**/cout<<"["<<i<<"] ";
            for(auto p:data[i]){
                auto index=find(all(chem),p.first)-chem.begin();
                mat[index][i]=p.second*(i+1==data.size()?-1:1);
                //**/cout<<"<"<<p.first<<":"<<p.second<<"> ";
            }
            //**/cout<<endl;
        }
        int s=mat[0].size()-1;
        //**/[&chem,mat]{rep(i,chem.size()){cout<<chem[i]<<" : ";for(int j=0 ; j<mat[i].size();j++)cout<<mat[i][j]<<(j+2==mat[i].size()?" | ":", ");cout<<endl;}cout<<"==========\n";}();
        rep(i,s){
            for(int j=i;j<mat.size();j++){
                if(mat[j][i]!=0){
                    swap(mat[i],mat[j]);
                    break;
                }
            }
            for(int j=0;j<mat.size();j++){
                if(j==i) continue;
                if(mat[j][i]!=0){
                    int gc=gcd(abs(mat[j][i]),abs(mat[i][i]));
                    int mx=gc/mat[i][i];
                    int ox=gc/mat[j][i];
                    for(int k=0;k<s+1;k++){
                        mat[j][k]=mat[j][k]*ox-mat[i][k]*mx;
                    }
                }
            }
        }
        int agc=1;
        for(int i=0;i<s;i++){
            if(mat[i][i]<0){
                mat[i][i]*=-1; mat[i][s]*=-1;
            }
            int lc=lcm(mat[i][i],mat[i][s]);
            if(lc!=1){
                mat[i][i]/=lc; mat[i][s]/=lc;
            }
            agc=gcd(agc,mat[i][i]);
        }
        for(int i=0;i<s;i++){
            mat[i][s]*=agc/mat[i][i];
            //**/mat[i][i]=agc;
            cout<<mat[i][s]<<" ";
        }
        cout<<agc<<endl;
        //[&chem,mat]{rep(i,chem.size()){cout<<chem[i]<<" : ";for(int j=0 ; j<mat[i].size();j++)cout<<mat[i][j]<<(j+2==mat[i].size()?" | ":", ");cout<<endl;}cout<<"=========="<<endl;}();
    }
}

Measured memory_bytes: 3184