#include <bits/stdc++.h>
using namespace std;
int t, n, m;
long long r, ans[800005];
stack<int> s;
vector<pair<char, vector<int>>> v;
char x[800005 * 6];
void dfs(int a) {
  if (v[a].first == '_') return;
  vector<int> tv;
  for (int i : v[a].second) {
    dfs(i);
    if (v[a].first == v[i].first) {
      if (tv.size() < v[i].second.size()) tv.swap(v[i].second);
      tv.insert(tv.end(), v[i].second.begin(), v[i].second.end());
    } else
      tv.push_back(i);
  }
  v[a].second.swap(tv);
  if (v[a].first == 'S') {
    int best = v[a].second.front();
    for (int i : v[a].second)
      if (v[i].second.size() < v[best].second.size()) best = i;
    v[a].first = v[best].first;
    v[a].second.swap(v[best].second);
  }
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%lld ", &r);
    fgets(x, sizeof(x), stdin);
    x[n = strlen(x) - 1] = 0;
    if (n == 1) {
      printf("REVOLTING %lld\n", r);
      continue;
    }
    m = 0;
    s = stack<int>();
    s.push(0);
    v = {{'S', vector<int>()}};
    for (int i = 0; i < n; i++) {
      if (x[i] == '(') {
        s.push(v.size());
        v.emplace_back('?', vector<int>());
      } else if (x[i] == ')') {
        int tmp = s.top();
        s.pop();
        v[s.top()].second.push_back(tmp);
      } else if (x[i] == '*') {
        v[s.top()].second.push_back(v.size());
        v.emplace_back('_', vector<int>{m++});
      } else if (x[i] != ' ')
        v[s.top()].first = x[i];
    }
    dfs(0);
    if (v[0].first == '_')
      ans[v[0].second.front()] = r;
    else
      for (int i : v[0].second)
        ans[v[i].second.front()] = (long long)r * v[0].second.size();
    printf("REVOLTING");
    for (int i = 0; i < m; i++) {
      printf(" %lld", ans[i]);
      ans[i] = 0;
    }
    puts("");
  }
}
