#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0;
  bool flg = false;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') flg = true;
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);
  return flg ? -x : x;
}
int lim;
long long W;
long long w[80010];
int n, m;
char s[1 << 20];
int len, C;
vector<int> e[1 << 20];
int f[1 << 20];
bool g[1 << 20];
int dfs1() {
  int x = ++n;
  e[x].clear();
  if (s[C++] == '*') return x;
  while (1) {
    e[x].push_back(dfs1());
    if (s[C++] == ')') break;
    g[x] = s[C - 1] == 'P';
  }
  return x;
}
void dfs2(int x) {
  f[x] = 0;
  if (e[x].empty()) return f[x] = 1, void();
  if (g[x]) {
    for (const int &y : e[x]) dfs2(y), f[x] += f[y];
  } else {
    f[x] = 1e9;
    for (const int &y : e[x]) dfs2(y), f[x] = min(f[x], f[y]);
  }
}
void dfs3(int x, bool h) {
  if (e[x].empty()) {
    w[++m] = 0;
    if (h) w[m] = W;
    return;
  }
  if (g[x]) {
    for (const int &y : e[x]) dfs3(y, h);
  } else {
    int t = -1;
    for (const int &y : e[x])
      if (f[y] == f[x]) {
        t = y;
        break;
      }
    for (const int &y : e[x]) dfs3(y, h && t == y);
  }
}
void solve() {
  lim = read();
  n = m = 0;
  len = 0;
  C = 1;
  for (char c = getchar(); c != '\n' && c != '\r'; c = getchar()) {
    if (c == '(' || c == ')' || c == 'P' || c == 'S' || c == '*') s[++len] = c;
  }
  int rt = dfs1();
  dfs2(rt);
  W = 1LL * lim * f[rt];
  dfs3(rt, 1);
  printf("REVOLTING ");
  for (int i(1), _i(m); i <= _i; i++) printf("%lld ", w[i]);
  puts("");
}
int main() {
  for (int T = read(); T--;) solve();
  return 0;
}
