#include <bits/stdc++.h>
using namespace std;
void cal(string &s, long long a[], long long type[], vector<long long> v[],
         int i = 0) {
  if (s[i] == '*') {
    a[i] = 1;
    type[i] = -2;
    return;
  }
  if (s[v[i][1] - 2] == 'P')
    type[i] = -1;
  else
    type[i] = 0;
  cal(s, a, type, v, v[i][0]);
  a[i] = a[v[i][0]];
  for (int j = 1; j < v[i].size(); j++) {
    cal(s, a, type, v, v[i][j]);
    long long x = a[v[i][j]];
    if (type[i] == -1)
      a[i] += x;
    else if (x < a[i]) {
      type[i] = j;
      a[i] = x;
    }
  }
}
void cal2(long long a[], long long type[], vector<long long> v[],
          long long ans[], long double r, long long i = 0) {
  if (type[i] == -2) {
    ans[i] = round(r);
    return;
  }
  if (type[i] == -1) {
    for (auto j : v[i]) cal2(a, type, v, ans, (r * a[i]) / a[j], j);
    return;
  }
  for (int j = 0; j < v[i].size(); j++)
    if (j == type[i])
      cal2(a, type, v, ans, r, v[i][j]);
    else
      cal2(a, type, v, ans, 0, v[i][j]);
}
void solve() {
  long long r, i;
  string s = "";
  cin >> r;
  getline(cin, s);
  s.erase(0, 1);
  long long a[s.length()], type[s.length()], ans[s.length()];
  vector<long long> v[s.length()], vec;
  vec.push_back(0);
  for (i = 1; i < s.length(); i++) {
    if (s[i] == '*') v[*vec.rbegin()].push_back(i);
    if (s[i] == ')') vec.pop_back();
    if (s[i] == '(') {
      v[*vec.rbegin()].push_back(i);
      vec.push_back(i);
    }
  }
  cal(s, a, type, v);
  cal2(a, type, v, ans, r);
  cout << "REVOLTING ";
  for (i = 0; i < s.length(); i++)
    if (s[i] == '*') cout << ans[i] << " ";
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t, i;
  cin >> t;
  while (t--) solve();
  return 0;
}
