#include <bits/stdc++.h>
const int maxn = 1e6 + 6;
using namespace std;
int rd() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = (x << 3) + (x << 1) + c - '0', c = getchar();
  return x * f;
}
int T, sta[maxn], top, to[maxn], tag[maxn], id[maxn], dfn, vis[maxn], num, cnt;
string s;
int R, f[maxn];
vector<int> G[maxn];
void build() {
  int len = s.size();
  for (int i = 0; i < len; i++) {
    if (s[i] == '(') {
      G[++num].clear();
      if (top) G[sta[top]].push_back(num);
      sta[++top] = num;
      vis[num] = to[num] = f[num] = 0;
    } else if (s[i] == '*') {
      G[++num].clear();
      if (top) G[sta[top]].push_back(num);
      vis[num] = to[num] = f[num] = 0;
    } else if (s[i] == 'S')
      tag[sta[top]] = 1;
    else if (s[i] == 'P')
      tag[sta[top]] = 0;
    else if (s[i] == ')')
      top--;
  }
}
void dfs(int u) {
  if (!((int)G[u].size())) {
    f[u] = 1;
    id[u] = ++dfn;
    return;
  }
  for (int v : G[u]) dfs(v);
  if (tag[u]) {
    int mi = 0;
    for (int v : G[u])
      if (f[mi] > f[v]) mi = v;
    f[u] = f[mi];
    to[u] = mi;
  } else
    for (int v : G[u]) f[u] += f[v];
}
void getans(int u) {
  if (!((int)G[u].size())) {
    vis[id[u]] = 1;
    ++cnt;
    return;
  }
  if (tag[u] && to[u])
    getans(to[u]);
  else
    for (int v : G[u]) getans(v);
}
int main() {
  T = rd();
  f[0] = 2e9;
  for (; T; T--) {
    R = rd();
    getline(cin, s);
    num = dfn = top = 0;
    build();
    dfs(1);
    cnt = 0;
    getans(1);
    printf("REVOLTING ");
    for (int i = 1; i <= dfn; i++)
      printf("%lld ", vis[i] ? 1LL * R * cnt : 0LL);
    puts("");
  }
  return 0;
}
