#include <bits/stdc++.h>
using namespace std;
int Size[300005];
int f[300005];
int Find(int first) {
  if (f[first] == first) return first;
  return f[first] = Find(f[first]);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long r;
    scanf("%lld", &r);
    vector<pair<int, char> > v;
    char c[5000005];
    int Index = 0;
    scanf(" %c", &c[0]);
    int now = 1;
    while (scanf("%c", &c[now])) {
      c[now + 1] = 0;
      if (c[now] == '\n') {
        c[now] = 0;
        break;
      } else {
        now++;
      }
    }
    for (int i = 0; c[i] != 0; i++) {
      if (c[i] == '*') {
        Size[Index] = 1;
        f[Index] = Index;
        v.push_back(make_pair(Index++, 0));
      } else if (c[i] == ')') {
        int S = 0, P = 0;
        int tmp = -1;
        while (v.back().second != '(') {
          if (v.back().second == 0) {
            if (S) {
              int a = Find(tmp), b = Find(v.back().first);
              if (Size[a] > Size[b]) tmp = v.back().first;
            } else {
              if (tmp == -1) {
                tmp = v.back().first;
              } else {
                int a = Find(tmp), b = Find(v.back().first);
                f[b] = a;
                Size[a] += Size[b];
              }
            }
          } else {
            if (v.back().second == 'S')
              S = 1;
            else
              P = 1;
          }
          v.pop_back();
        }
        v.pop_back();
        v.push_back(make_pair(tmp, 0));
      } else if (c[i] != ' ') {
        v.push_back(make_pair(0, c[i]));
      }
    }
    printf("REVOLTING");
    for (int i = 0; i < Index; i++) {
      if (Find(i) == v.back().first)
        printf(" %lld", Size[v.back().first] * r);
      else
        printf(" 0");
    }
    printf("\n");
  }
}
