#include <bits/stdc++.h>
using namespace std;
const int dbg = 0;
struct FatalMessage {
  FatalMessage(const char* file, int line, const char* cond) {
    std::cerr << file << " L" << line << " failed: " << cond << ". ";
  }
  ~FatalMessage() {
    std::cerr << std::endl;
    std::terminate();
  }
};
template <typename T>
const FatalMessage& operator<<(const FatalMessage& s, const T& t) {
  std::cerr << t;
  return s;
}
template <typename C>
void SortAndUniq(C& c) {
  sort(c.begin(), c.end());
  c.erase(unique(c.begin(), c.end()), c.end());
}
vector<int> next_link;
struct Repr {
  int size, head, tail;
  void Append(const Repr& o) {
    size += o.size;
    next_link[tail] = o.head;
    tail = o.tail;
  }
};
struct Net {
  static int next_id;
  static pair<Repr, const char*> Parse(const char* p) {
    if (*p == '*') {
      int id = next_id++;
      if (next_link.size() <= id) {
        next_link.resize(id + 1);
      }
      next_link[id] = -1;
      return {Repr{1, id, id}, p + 1};
    }
    if (*p == '(')
      ;
    else
      FatalMessage("<stdin>", 53, "*p == '('");
    Repr r;
    tie(r, p) = Parse(p + 1);
    if (*p == 'S' || *p == 'P')
      ;
    else
      FatalMessage("<stdin>", 56, "*p == 'S' || *p == 'P'");
    char oper = *p;
    for (;;) {
      Repr s;
      tie(s, p) = Parse(p + 1);
      if (oper == 'S') {
        if (s.size < r.size) {
          r = s;
        }
      } else {
        r.Append(s);
      }
      if (*p == ')') {
        break;
      }
      if (*p == oper)
        ;
      else
        FatalMessage("<stdin>", 71, "*p == oper");
    }
    return {move(r), p + 1};
  }
};
int Net::next_id;
void Solve() {
  long long R;
  cin >> R;
  string s;
  getline(cin, s);
  s.erase(remove_if(s.begin(), s.end(),
                    [](char c) {
                      return c != '(' && c != ')' && c != 'S' && c != 'P' &&
                             c != '*';
                    }),
          s.end());
  Net::next_id = 0;
  auto n = Net::Parse(s.c_str()).first;
  vector<char> is(Net::next_id, false);
  for (int p = n.head; p != -1; p = next_link[p]) {
    is[p] = true;
  }
  cout << "REVOLTING";
  for (int i = 0; i < Net::next_id; ++i) {
    long long t = 0;
    if (is[i]) {
      t = n.size * R;
    }
    cout << ' ' << t;
  }
  cout << '\n';
}
int main() {
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  int T;
  for (cin >> T; T--;) {
    Solve();
  }
}
