#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
struct Node {
  char type;
  long long idx;
  long long p;
  vector<long long> chd;
  long long s;
  long long on;
  long long r;
};
long long dfs(Node& node, vector<Node>& nls) {
  node.on = 1;
  if (node.type == '*') {
    node.s = 1;
    return 1;
  }
  if (node.type == 'P') {
    long long sum = 0;
    for (auto c : node.chd) {
      sum += dfs(nls[c], nls);
    }
    node.s = sum;
    return sum;
  } else {
    long long mmin = 80001;
    for (auto c : node.chd) {
      mmin = min(mmin, dfs(nls[c], nls));
    }
    int find = 0;
    for (auto c : node.chd) {
      if (find == 0 && nls[c].s == mmin) {
        find = 1;
        nls[c].on = 1;
      } else {
        nls[c].on = 0;
      }
    }
    node.s = mmin;
    return mmin;
  }
}
void dfs2(Node& node, vector<Node>& nls, long long v) {
  if (node.on == 0) {
    return;
  }
  if (node.type == '*') {
    node.r = v;
    return;
  }
  for (auto c : node.chd) {
    dfs2(nls[c], nls, v);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    vector<Node> nls;
    nls.push_back(Node());
    long long r;
    cin >> r;
    char c;
    int n = 0;
    int cnt = 1;
    long long par = 0;
    do {
      cin >> c;
      if (c == '(') {
        ++par;
        Node node;
        node.idx = cnt;
        node.r = 0;
        node.p = n;
        nls.push_back(node);
        nls[n].chd.push_back(cnt);
        n = cnt;
        ++cnt;
      } else if (c == ')') {
        --par;
        n = nls[n].p;
      } else if (c == 'P') {
        nls[n].type = c;
      } else if (c == 'S') {
        nls[n].type = c;
      } else if (c == '*') {
        Node node;
        node.idx = cnt;
        node.r = 0;
        node.p = n;
        node.type = c;
        nls.push_back(node);
        nls[n].chd.push_back(cnt);
        ++cnt;
      }
    } while (par);
    long long sum = dfs(nls[0], nls);
    dfs2(nls[0], nls, r * sum);
    cout << "REVOLTING ";
    for (int j = 1; j < cnt; ++j) {
      if (nls[j].type == '*') {
        cout << nls[j].r << ' ';
      }
    }
    cout << "\n";
  }
  return 0;
}
