#include <bits/stdc++.h>
using namespace std;
enum Type {
  SINGLE,
  SERIES,
  PARALLEL,
};
struct Node {
  Type type;
  vector<shared_ptr<Node>> children;
  long long multiplier;
};
shared_ptr<Node> parse() {
  auto ptr = make_shared<Node>();
  char c;
  cin >> c;
  if (c == '*') {
    ptr->type = SINGLE;
    return ptr;
  }
  assert(c == '(');
  ptr->children.push_back(parse());
  cin >> c;
  if (c == 'S') {
    ptr->type = SERIES;
  } else {
    assert(c == 'P');
    ptr->type = PARALLEL;
  }
  while (c != ')') {
    ptr->children.push_back(parse());
    cin >> c;
  }
  return ptr;
}
void compute_multiplier(shared_ptr<Node> p) {
  if (p->type == SINGLE) {
    p->multiplier = 1;
    assert(p->children.empty());
    return;
  }
  assert(p->children.size() >= 2);
  for (auto& child : p->children) {
    compute_multiplier(child);
  }
  if (p->type == SERIES) {
    p->multiplier = p->children.front()->multiplier;
    for (auto& child : p->children) {
      p->multiplier = min(p->multiplier, child->multiplier);
    }
    return;
  }
  assert(p->type == PARALLEL);
  p->multiplier = 0;
  for (auto& child : p->children) {
    p->multiplier += child->multiplier;
  }
}
long long gcd(long long x, long long y) {
  if (y == 0) {
    return x;
  }
  return gcd(y, x % y);
}
void reduce(pair<long long, long long>& x) {
  assert(x.second != 0);
  long long g = gcd(x.first, x.second);
  x.first /= g;
  x.second /= g;
}
pair<long long, long long> multiply(pair<long long, long long> x,
                                    pair<long long, long long> y) {
  reduce(x);
  reduce(y);
  pair<long long, long long> res(x.first * y.first, x.second * y.second);
  reduce(res);
  return res;
}
void solve(shared_ptr<Node> p, pair<long long, long long> ohms) {
  if (p->type == SINGLE) {
    assert(ohms.second == 1);
    cout << " " << ohms.first;
    return;
  }
  int n = p->children.size();
  if (p->type == SERIES) {
    int index = -1;
    for (int i = 0; i < n; ++i) {
      if (p->children[i]->multiplier == p->multiplier) {
        index = i;
        break;
      }
    }
    for (int i = 0; i < n; ++i) {
      if (i == index) {
        solve(p->children[i], ohms);
      } else {
        solve(p->children[i], make_pair(0, 1));
      }
    }
    return;
  }
  assert(p->type == PARALLEL);
  for (int i = 0; i < n; ++i) {
    auto target =
        multiply(ohms, make_pair(p->multiplier, p->children[i]->multiplier));
    solve(p->children[i], target);
  }
}
int main() {
  int tcas;
  cin >> tcas;
  for (int cas = 0; cas < tcas; ++cas) {
    int n;
    cin >> n;
    auto p = parse();
    compute_multiplier(p);
    cout << "REVOLTING";
    solve(p, make_pair(n, 1));
    cout << endl;
  }
}
