#include <bits/stdc++.h>
using namespace std;
struct __timestamper {};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  string s;
  while (T--) {
    int r;
    cin >> r;
    enum type { LEAF, SERIES, PARALLEL };
    struct node {
      type t;
      vector<node*> e;
      long double sum;
    };
    getline(cin, s);
    int cur = 0;
    auto skip_spaces = [&]() {
      while (cur < (int)s.length() && s[cur] == ' ') cur++;
    };
    auto get_symbol = [&]() {
      skip_spaces();
      assert(cur < (int)s.length());
      return s[cur++];
    };
    function<node*()> parse = [&]() {
      node* res = new node();
      char c = get_symbol();
      if (c == '*') {
        res->t = LEAF;
      } else {
        res->e.push_back(parse());
        res->t = LEAF;
        while (1) {
          c = get_symbol();
          if (c == ')') break;
          assert(c == 'S' || c == 'P');
          auto old = res->t;
          if (c == 'S')
            res->t = SERIES;
          else
            res->t = PARALLEL;
          assert(old == LEAF || old == res->t);
          res->e.push_back(parse());
        }
      }
      return res;
    };
    node* root = parse();
    function<void(node*)> dfs = [&](node* root) {
      if (root->t == LEAF) {
        root->sum = 1;
        return;
      }
      if (root->t == SERIES) {
        root->sum = 1e20;
        for (auto to : root->e) {
          dfs(to);
          root->sum = min(root->sum, to->sum);
        }
        return;
      }
      root->sum = 0;
      vector<long double> v;
      for (auto to : root->e) {
        dfs(to);
        v.push_back(to->sum);
      }
      long double sumsqrt = 0;
      for (int i = 0; i < (int)v.size(); i++) {
        root->sum += v[i];
        sumsqrt += sqrt(v[i]);
      }
      for (int i = 0; i < (int)v.size(); i++) {
        root->sum += sqrt(v[i]) * (sumsqrt - sqrt(v[i]));
      }
    };
    dfs(root);
    vector<long long> ans;
    function<void(node*, long double)> dfs2 = [&](node* root, long double r) {
      if (root->t == LEAF) {
        ans.push_back(round(r));
        assert(fabs(r - round(r)) < 1e-3);
        return;
      }
      if (root->t == SERIES) {
        int j = 0;
        for (int i = 1; i < (int)root->e.size(); i++)
          if (root->e[i]->sum < root->e[j]->sum) j = i;
        for (int i = 0; i < (int)root->e.size(); i++) {
          dfs2(root->e[i], i == j ? r : 0);
        }
        return;
      }
      long double sumsqrt = 0;
      for (int i = 0; i < (int)root->e.size(); i++) {
        sumsqrt += sqrt(root->e[i]->sum);
      }
      for (int i = 0; i < (int)root->e.size(); i++) {
        long double nr =
            r * ((sumsqrt - sqrt(root->e[i]->sum)) / sqrt(root->e[i]->sum) + 1);
        dfs2(root->e[i], nr);
      }
    };
    dfs2(root, r);
    cout << "REVOLTING";
    for (auto x : ans) cout << " " << x;
    cout << "\n";
  }
  return 0;
}
