#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "URDL";
const long long MOD2 = (long long)1000000007 * (long long)1000000007;
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 1000000007) {
  x += y;
  if (x >= mod) x -= mod;
  if (x < 0) x += mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
char s[3001335];
int id[3001335], cnt;
int mt[3001335];
inline vector<int> cal(int l, int r) {
  vector<int> ans;
  if (l + 2 == r) {
    assert(s[l + 1] == '*');
    ans.push_back(id[l + 1]);
    return ans;
  }
  bool fg = 1;
  for (int i = l + 1; i < r;) {
    vector<int> tmp = cal(i, mt[i]);
    if (fg) {
      if (tmp.size() > ans.size()) swap(ans, tmp);
      for (int z : tmp) ans.push_back(z);
    } else {
      if (tmp.size() < ans.size()) swap(ans, tmp);
    }
    i = mt[i] + 1;
    if (i < r) {
      assert(s[i] == 'P' || s[i] == 'S');
      if (s[i] == 'S') fg = 0;
      i++;
    }
  }
  return ans;
}
void fmain(int tid) {
  int r;
  scanf("%d", &r);
  n = 0;
  cnt = 0;
  while (1) {
    char x = getchar();
    if (x == '\n') break;
    if (x == ' ') continue;
    if (x == '*') {
      s[++n] = '(';
      s[++n] = '*';
      id[n] = ++cnt;
      s[++n] = ')';
    } else
      s[++n] = x;
  }
  vector<int> vp;
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    if (s[i] == '(')
      vp.push_back(i);
    else if (s[i] == ')') {
      int x = vp.back();
      vp.pop_back();
      mt[x] = i;
      mt[i] = x;
    }
  }
  vector<int> ans = cal(1, n);
  vector<bool> vis(cnt + 1, 0);
  for (int z : ans) vis[z] = 1;
  printf("REVOLTING");
  for (int(i) = 1; (i) <= (int)(cnt); (i)++)
    if (vis[i]) {
      printf(" %lld", (long long)r * ans.size());
    } else
      printf(" 0");
  puts("");
}
int main() {
  int t = 1;
  scanf("%d", &t);
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
