#include <bits/stdc++.h>
using namespace std;
vector<int> e[200005];
int f[200005], id[200005], dfs_cnt;
bool col[200005], ban[200005];
void dfs1(int x) {
  if (!e[x].size()) {
    id[x] = ++dfs_cnt;
    f[x] = 1;
    return;
  }
  if (!col[x]) {
    int minn = 0;
    for (int i = 0; i < e[x].size(); i++) {
      int u = e[x][i];
      dfs1(u);
      if (f[u] < f[minn]) minn = u;
    }
    f[x] = f[minn];
    for (int i = 0; i < e[x].size(); i++)
      if (e[x][i] != minn) ban[e[x][i]] = 1;
  } else {
    for (int i = 0; i < e[x].size(); i++) {
      int u = e[x][i];
      dfs1(u);
      f[x] += f[u];
    }
  }
}
bool vis[200005];
void dfs2(int x) {
  if (!e[x].size()) {
    vis[id[x]] = 1;
    return;
  }
  for (int i = 0; i < e[x].size(); i++)
    if (!ban[e[x][i]]) dfs2(e[x][i]);
}
char str[2000005];
int st[2000005];
void build(int n) {
  int sz = 0, top = 0;
  for (int i = 1; i <= n; i++)
    if (str[i] == '(') {
      e[++sz].clear();
      if (top) e[st[top]].push_back(sz);
      st[++top] = sz;
      ban[sz] = vis[sz] = f[sz] = 0;
    } else if (str[i] == '*') {
      e[++sz].clear();
      ban[sz] = vis[sz] = f[sz] = 0;
      if (top) e[st[top]].push_back(sz);
    } else if (str[i] == 'S')
      col[st[top]] = 0;
    else if (str[i] == 'P')
      col[st[top]] = 1;
    else if (str[i] == ')')
      top--;
}
int main() {
  int cases;
  scanf("%d", &cases);
  for (; cases; cases--) {
    int r;
    scanf("%d", &r);
    cin.getline(str, 2e6);
    int len = strlen(str + 1);
    build(len);
    dfs_cnt = 0;
    f[0] = 0x3f3f3f3f;
    dfs1(1);
    dfs2(1);
    int s = 0;
    for (int i = 1; i <= dfs_cnt; i++) s += vis[i];
    printf("REVOLTING ");
    for (int i = 1; i <= dfs_cnt; i++)
      printf("%lld ", (vis[i]) ? (long long)s * r : 0LL);
    printf("\n");
  }
  return 0;
}
