#include <algorithm>
#include <cctype>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;


long long gcd(long long a, long long b) {
  int k = 1;
  if (a < 0) {
    k = -k;
    a = -a;
  }
  if (b < 0) {
    k = -k;
    b = -b;
  }
  while (b > 0) {
    a %= b;
    swap(a, b);
  }
  return k * a;
}

long long lcm(long long a, long long b) {
  return a * b / gcd(a, b);
}

class Solver {
  typedef vector<long long> Vec;
  typedef unordered_map<string, Vec> Dict;
  public:
    string line;
    Vec solve() {
      Dict dic = chemical_equation();
      return solve_le(dic);
    }
  private:
    Vec solve_le(const Dict &dic) {
      size_t n;
      long long q = 1;
      vector<Vec> a;
      Vec ans;
      for (auto &p : dic) {
        a.push_back(p.second);
      }
      n = a[0].size();
      for (size_t i = 0; i < n - 1; ++i) {
        size_t p = i;
        for (size_t j = i + 1; j < a.size(); ++j) {
          if (abs(a[j][i]) > abs(a[p][i])) {
            p = j;
          }
        }
        swap(a[i], a[p]);
        for (size_t j = 0; j < a.size(); ++j) {
          if (j != i and a[j][i] != 0) {
            long long m = lcm(a[i][i], a[j][i]);
            long long x = m / a[i][i];
            long long y = m / a[j][i];
            for (size_t k = 0; k < n; ++k) {
              a[j][k] = a[j][k] * y - a[i][k] * x;
            }
          }
        }
      }
      for (size_t i = 0; i < n - 1; ++i) {
        q = lcm(q, lcm(a[i][i], -a[i][n - 1]) / (-a[i][n - 1]));
      }
      for (size_t i = 0; i < n - 1; ++i) {
        ans.push_back(q * (-a[i][n - 1]) / a[i][i]);
      }
      ans.push_back(q);
      return ans;
    }
    Dict chemical_equation(int pos = 0) {
      Dict d = molecule_sequence(pos);
      pos += 2;
      for (auto &p : molecule_sequence(pos)) {
        Vec &v = d[p.first];
        for (auto x : p.second) {
          v.push_back(-x);
        }
      }
      return d;
    }
    Dict molecule_sequence(int &pos) {
      Dict d = molecule(pos);
      size_t n = 0;
      size_t m = 0;
      for (auto &p : d) {
        n = max(n, p.second.size());
      }
      if (line[pos] == '+') {
        ++pos;
        for (auto &p : molecule_sequence(pos)) {
          Vec &v = d[p.first];
          while (v.size() < n) {
            v.push_back(0);
          }
          v.insert(v.end(), p.second.begin(), p.second.end());
          m = max(m, v.size());
        }
        for (auto &p : d) {
          Vec &v = p.second;
          while (v.size() < m) {
            v.push_back(0);
          }
        }
      }
      return d;
    }
    Dict molecule(int &pos) {
      Dict d = group(pos);
      if (line[pos] == '(' or isupper(line[pos])) {
        for (auto &p : molecule(pos)) {
          Vec &v = d[p.first];
          if (v.size() == 0) {
            v.push_back(0);
          }
          v[0] += p.second[0];
          for (auto &p : d) {
            Vec &v = p.second;
            while (v.size() == 0) {
              v.push_back(0);
            }
          }
        }
      }
      return d;
    }
    Dict group(int &pos) {
      Dict d = unit_group(pos);
      long long x = max(1LL, number(pos));
      for (auto &p : d) {
        p.second[0] *= x;
      }
      return d;
    }
    Dict unit_group(int &pos) {
      Dict d;
      if (line[pos] == '(') {
        ++pos;
        d = molecule(pos);
        ++pos;
      } else {
        d = chemical_element(pos);
      }
      return d;
    }
    Dict chemical_element(int &pos) {
      Dict d;
      string s;
      if (islower(line[pos + 1])) {
        s = line.substr(pos, 2);
        pos += 2;
      } else {
        s = line.substr(pos, 1);
        ++pos;
      }
      d[s].push_back(1);
      return d;
    }
    long long number(int &pos) {
      long long x = 0;
      while (isdigit(line[pos])) {
        x = 10 * x + line[pos] - '0';
        ++pos;
      }
      return x;
    }
};

int main() {
  Solver s;
  while (true) {
    bool is_first = true;
    cin >> s.line;
    if (s.line == ".") {
      return 0;
    }
    for (auto k : s.solve()) {
      if (is_first) {
        is_first = false;
      } else {
        cout << ' ';
      }
      cout << k;
    }
    cout << endl;
  }
}

Measured memory_bytes: 3212