#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 50;
int T, n;
string S;
vector<int> G[N];
bool a[N], ex[N];
long long k[N], r;
void dfs(int u) {
  ex[u] = true, k[u] = 0;
  if (!G[u].size()) return k[u] = 1, void();
  for (int v : G[u]) dfs(v);
  if (!a[u]) {
    long long mn = 1e18;
    int t = 0;
    for (int v : G[u])
      if (k[v] < mn) mn = k[v], t = v;
    k[u] = mn;
    for (int v : G[u])
      if (t != v) ex[v] = false;
  } else
    for (int v : G[u]) k[u] += k[v];
}
void cope(int u) {
  for (int v : G[u]) ex[v] &= ex[u], cope(v);
}
void Main() {
  scanf("%d", &r);
  getline(cin, S);
  int len = S.length();
  static int stk[N];
  int top = 0;
  n = 0;
  G[0].clear();
  vector<int> z;
  for (int i = 1; i <= len; i++) {
    if (S[i] == '(') {
      int u = ++n;
      G[u].clear();
      G[stk[top]].push_back(u);
      stk[++top] = u;
    } else if (S[i] == ')')
      --top;
    else if (S[i] == '*') {
      int u = ++n;
      G[u].clear();
      G[stk[top]].push_back(u), z.push_back(u);
    } else if (S[i] == 'S')
      a[stk[top]] = 0;
    else if (S[i] == 'P')
      a[stk[top]] = 1;
  }
  dfs(1), cope(1);
  cout << "REVOLTING ";
  for (int o : z) cout << (ex[o] ? k[1] * r : 0) << " ";
  puts("");
}
int main() {
  cin >> T;
  while (T--) Main();
  return 0;
}
