#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while (((c = getchar()) == ' ') || c == '\n')
    ;
  x = c;
}
int t, n, j, m, r, i, stk[1000005], tp, typ[1000005], cnt, f[1000005];
vector<int> e[1000005];
long long ans[1000005];
void dfs1(int x) {
  if (typ[x] == 0) {
    f[x] = 1;
  }
  if (typ[x] == 1) {
    f[x] = 0;
    for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end();
         it++) {
      dfs1(*it);
      f[x] += f[*it];
    }
  }
  if (typ[x] == 2) {
    f[x] = 0x3f3f3f3f;
    for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end();
         it++) {
      dfs1(*it);
      f[x] = min(f[x], f[*it]);
    }
  }
}
void dfs2(int x, long long t) {
  if (typ[x] == 0) {
    ans[x] = t;
  }
  if (typ[x] == 1) {
    for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end();
         it++) {
      dfs2(*it, t);
    }
  }
  if (typ[x] == 2) {
    for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end();
         it++) {
      if (f[*it] == f[x]) {
        dfs2(*it, t);
        return;
      }
    }
  }
}
int main() {
  read(t);
  while (t--) {
    read(r);
    cnt = 0;
    for (;;) {
      char c = getchar();
      if (c == '\n') break;
      if (c == '(') {
        if (tp) e[stk[tp]].push_back(cnt + 1);
        stk[++tp] = ++cnt;
        e[cnt].clear();
      }
      if (c == ')') {
        tp--;
      }
      if (c == '*') {
        typ[++cnt] = 0;
        e[cnt].clear();
        e[stk[tp]].push_back(cnt);
      }
      if (c == 'P') {
        typ[stk[tp]] = 1;
      }
      if (c == 'S') {
        typ[stk[tp]] = 2;
      }
    }
    dfs1(1);
    for (((i)) = (1); ((i)) <= ((cnt)); ((i))++) ans[i] = 0;
    dfs2(1, 1ll * f[1] * r);
    printf("REVOLTING");
    for (((i)) = (1); ((i)) <= ((cnt)); ((i))++)
      if (!typ[i]) printf(" %lld", ans[i]);
    puts("");
  }
  return 0;
}
