#include <bits/stdc++.h>
using namespace std;
int globaloffset = 0;
struct Node {
  vector<int> idx;
  vector<Node*> add;
  int sz = 0;
  Node(vector<int> vals) : idx(vals) { sz = 0; }
};
pair<Node*, int> getlen(string& s, int ps) {
  char op = 'U';
  Node* rep = new Node({});
  int i;
  for (i = ps; i < s.length();) {
    if (s[i] == '*') {
      if (op != 'S') {
        rep->idx.push_back(globaloffset);
        ++rep->sz;
      } else if (op == 'S') {
        rep->idx.clear();
        rep->idx.push_back(globaloffset);
        rep->add.clear();
        rep->sz = 1;
      }
      ++globaloffset;
      ++i;
    } else if (s[i] == 'P') {
      op = 'P';
      ++i;
    } else if (s[i] == 'S') {
      op = 'S';
      ++i;
    } else if (s[i] == '(') {
      auto curids = getlen(s, i + 1);
      int nps = curids.second;
      if (op != 'S') {
        rep->add.push_back(curids.first);
        rep->sz += rep->add.back()->sz;
      } else {
        if (curids.first->sz < rep->sz) {
          rep = curids.first;
        }
      }
      i = nps;
    } else if (s[i] == ')') {
      ++i;
      return make_pair(rep, i);
    } else {
      ++i;
    }
  }
  return make_pair(rep, i);
}
void dfs(Node* v, vector<int>& ans) {
  if (!v) {
    return;
  }
  for (auto x : v->idx) {
    ans.push_back(x);
  }
  for (auto to : v->add) {
    dfs(to, ans);
  }
}
void solve() {
  string s;
  getline(cin, s);
  long long target = 0;
  int idx = 0;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] - '0' >= 0 && s[i] - '0' <= 9) {
      target *= 10;
      target += s[i] - '0';
    } else {
      idx = i;
      break;
    }
  }
  string toparse = "";
  for (int i = idx; i < s.length(); ++i) {
    if (s[i] != ' ') {
      toparse += s[i];
    }
  }
  globaloffset = 0;
  int id;
  Node* ret = getlen(toparse, 0).first;
  vector<int> res;
  dfs(ret, res);
  long long tot = 0;
  for (int i = 0; i < toparse.length(); ++i) {
    if (toparse[i] == '*') {
      ++tot;
    }
  }
  vector<long long> ans(tot, 0);
  for (int i = 0; i < res.size(); ++i) {
    ans[res[i]] = 1;
  }
  cout << "REVOLTING";
  for (int i = 0; i < ans.size(); ++i) {
    cout << " " << ans[i] * (long long)res.size() * target;
  }
  cout << endl;
}
void genbig() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  string s;
  getline(cin, s);
  int val = 0;
  for (int i = 0; i < s.length(); ++i) {
    val *= 10;
    val += s[i] - '0';
  }
  t = val;
  for (int tt = 0; tt < t; ++tt) {
    solve();
  }
  return 0;
}
