#include <bits/stdc++.h>
using namespace std;
int r;
string s;
void input() {
  s.clear();
  cin >> r;
  string buffer;
  getline(cin, buffer);
  for (auto i : buffer) {
    if (!isspace(i)) s += i;
  }
}
struct Solver {
  vector<vector<int>> adj;
  vector<int> type;
  int NODE = 1;
  long long int r;
  vector<long long int> rc, c, child;
  string s;
  Solver(int r0, string& str) {
    r = r0;
    int n = str.size();
    adj.resize(n + 3);
    rc.resize(n + 3);
    c.resize(n + 3);
    child.resize(n + 3);
    type.resize(n + 3);
    s = str;
  }
  void dfs1(int a) {
    if (adj[a].size() == 0) {
      c[a] = 1;
      return;
    }
    if (type[a] == 0) c[a] = 1000000000;
    for (auto i : adj[a]) {
      dfs1(i);
      if (type[a] == 0) {
        if (c[a] > c[i]) {
          c[a] = c[i];
          child[a] = i;
        }
      } else {
        c[a] += c[i];
      }
    }
  }
  void dfs2(int a) {
    for (auto i : adj[a]) {
      if (type[a] == 0) {
        if (i == child[a])
          rc[i] = rc[a];
        else
          rc[i] = 0;
      } else {
        rc[i] = rc[a];
      }
      dfs2(i);
    }
  }
  void solve() {
    vector<int> stack;
    vector<int> resistor;
    int cur = 1;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '(') {
        NODE++;
        stack.push_back(NODE);
        adj[cur].push_back(NODE);
        cur = NODE;
      }
      if (s[i] == '*') {
        NODE++;
        adj[cur].push_back(NODE);
        resistor.push_back(NODE);
      }
      if (s[i] == ')') {
        stack.pop_back();
        cur = stack.back();
      }
      if (s[i] == 'P') {
        type[cur] = 1;
      }
    }
    dfs1(1);
    rc[1] = r * c[1];
    dfs2(1);
    cout << "REVOLTING ";
    for (auto i : resistor) cout << rc[i] << " ";
    cout << endl;
  }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int t;
  cin >> t;
  for (int z = 1; z <= t; z++) {
    input();
    Solver(r, s).solve();
  }
  return 0;
}
