#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline T1 max(T1 a, T2 b) {
  return a < b ? b : a;
}
template <typename T1, typename T2>
inline T1 min(T1 a, T2 b) {
  return a < b ? a : b;
}
const char lf = '\n';
namespace ae86 {
const int bufl = 1 << 15;
char buf[bufl], *s = buf, *t = buf;
inline int fetch() {
  if (s == t) {
    t = (s = buf) + fread(buf, 1, bufl, stdin);
    if (s == t) return EOF;
  }
  return *s++;
}
inline int ty() {
  int a = 0;
  int b = 1, c = fetch();
  while (!isdigit(c)) b ^= c == '-', c = fetch();
  while (isdigit(c)) a = a * 10 + c - 48, c = fetch();
  return b ? a : -a;
}
inline int tc() {
  int c = fetch();
  while (c <= 32 && c != EOF) c = fetch();
  return c;
}
}  // namespace ae86
using ae86::tc;
using ae86::ty;
const int _ = 1000007, inf = 0x3f3f3f3f;
long long R, ans[_] = {0}, f[_] = {0};
int now, stk[_], top, opt[_] = {0};
vector<int> hav[_];
void dfs(int x) {
  if (!opt[x])
    f[x] = 1;
  else if (opt[x] == 1)
    f[x] = 0;
  else
    f[x] = inf;
  for (auto b : hav[x]) {
    dfs(b);
    if (opt[x] == 1)
      f[x] += f[b];
    else
      f[x] = min(f[x], f[b]);
  }
}
void dfs2(int x, long long v) {
  if (!opt[x]) {
    ans[x] = v * R;
    return;
  }
  if (opt[x] == 1) {
    for (auto b : hav[x]) dfs2(b, v);
    return;
  }
  for (auto b : hav[x])
    if (f[b] == f[x]) {
      dfs2(b, v);
      return;
    }
}
void finder() {
  R = ty();
  now = top = 0;
  while (1) {
    int c = ae86::fetch();
    if (c < 32) break;
    if (c == 32) continue;
    if (c == '(') {
      if (top) hav[stk[top]].emplace_back(now + 1);
      now++, hav[now].clear(), stk[++top] = now;
    } else if (c == ')')
      top--;
    else if (c == 'P')
      opt[stk[top]] = 1;
    else if (c == 'S')
      opt[stk[top]] = 2;
    else {
      if (top) hav[stk[top]].emplace_back(now + 1);
      now++, hav[now].clear(), opt[now] = 0;
    }
  }
  for (int i = 1; i <= now; i++) ans[i] = 0;
  dfs(1), dfs2(1, f[1]);
  cout << "REVOLTING";
  for (int i = 1; i <= now; i++)
    if (!opt[i]) cout << ' ' << ans[i];
  cout << lf;
}
int main() {
  ios::sync_with_stdio(0), cout.tie(nullptr);
  int t = ty();
  while (t--) finder();
  return 0;
}
