#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int T;
int n, m, r;
char s[1000000];
bool ispar[N];
vector<int> G[N];
int newnode() {
  ++n;
  G[n].clear();
  ispar[n] = false;
  return n;
}
int id[N];
int build(char*& s) {
  int p = newnode();
  while (true) {
    while (*s == ' ') s++;
    if (!*s || *s == ')') return p;
    if (*s == 'P') {
      ispar[p] = true;
    } else if (*s == 'S') {
      ispar[p] = false;
    } else if (*s == '(') {
      G[p].push_back(build(++s));
    } else if (*s == '*') {
      G[p].push_back(newnode());
      id[n] = ++m;
    }
    s++;
  }
  return p;
}
int f[N], g[N], R[N];
void dfs(int p) {
  if (G[p].empty()) {
    f[p] = 1;
    return;
  }
  if (!ispar[p]) {
    f[p] = 1e9;
    g[p] = -1;
    for (auto e : G[p]) {
      dfs(e);
      if (f[e] < f[p]) {
        f[p] = f[e];
        g[p] = e;
      }
    }
  } else {
    f[p] = 0;
    for (auto e : G[p]) {
      dfs(e);
      f[p] += f[e];
    }
  }
}
void dfs1(int p) {
  if (G[p].empty()) {
    R[id[p]] = 1;
    return;
  }
  if (ispar[p]) {
    for (auto e : G[p]) dfs1(e);
  } else {
    dfs1(g[p]);
  }
}
int main() {
  scanf("%d", &T);
  while (T--) {
    n = m = 0;
    scanf("%d", &r);
    gets(s);
    char* tmp = s;
    build(tmp);
    dfs(1);
    long long v = 1ll * r * f[1];
    for (int i = 1; i <= m; i++) {
      R[i] = 0;
    }
    dfs1(1);
    printf("REVOLTING");
    for (int i = 1; i <= m; i++) printf(" %lld", R[i] * v);
    putchar('\n');
  }
  return 0;
}
