#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int gi() {
  int x = 0, o = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') o = -1, ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
int r, op[N], tt, f[N], st[N], tp;
long long ans[N];
vector<int> E[N];
void dp(int u) {
  if (!op[u])
    f[u] = 1;
  else if (op[u] == 1)
    f[u] = 0;
  else
    f[u] = 1e9;
  for (auto v : E[u]) {
    dp(v);
    if (op[u] == 1)
      f[u] += f[v];
    else
      f[u] = min(f[u], f[v]);
  }
}
void getans(int u, int w) {
  if (!op[u]) {
    ans[u] = 1ll * w * r;
    return;
  }
  if (op[u] == 2) {
    for (auto v : E[u])
      if (f[u] == f[v]) {
        getans(v, w);
        break;
      }
  } else {
    for (auto v : E[u]) getans(v, w);
  }
}
int main() {
  int T = gi();
  while (T--) {
    r = gi();
    tt = 0;
    while (1) {
      char ch = getchar();
      if (ch == '\n') break;
      if (ch == ' ') continue;
      if (ch == '(') {
        if (tp) E[st[tp]].push_back(tt + 1);
        ++tt;
        E[tt].clear();
        st[++tp] = tt;
      } else if (ch == ')')
        --tp;
      else if (ch == 'P')
        op[st[tp]] = 1;
      else if (ch == 'S')
        op[st[tp]] = 2;
      else {
        if (tp) E[st[tp]].push_back(tt + 1);
        ++tt, op[tt] = 0, E[tt].clear();
      }
    }
    for (int i = 1; i <= tt; i++) ans[i] = 0;
    dp(1);
    getans(1, f[1]);
    cout << "REVOLTING ";
    for (int i = 1; i <= tt; i++)
      if (!op[i]) cout << ans[i] << ' ';
    cout << '\n';
  }
  return 0;
}
