#include <bits/stdc++.h>
using namespace std;
const int64_t INF = 1e18;
string str;
int strPtr;
char curChar() {
  while (str[strPtr] == ' ') ++strPtr;
  return str[strPtr];
}
char nextChar() {
  while (str[strPtr] == ' ') ++strPtr;
  ++strPtr;
  return curChar();
}
class Circuit {
 public:
  bool isSeries = 0;
  vector<int> childIds;
  int resistanceId = -1;
  int64_t weight = 0;
  Circuit() { childIds.clear(); }
  void giveBirth();
  void initResistance();
  void initJoined();
  void build();
  void putResistance(int64_t);
};
vector<Circuit> circuits;
vector<int64_t> resistances;
void Circuit::giveBirth() {
  int id = (int)circuits.size();
  childIds.push_back(id);
  circuits.emplace_back();
  circuits[id].build();
}
void Circuit::initResistance() {
  childIds.clear();
  resistanceId = (int)resistances.size();
  resistances.emplace_back(0);
  weight = 1;
}
void Circuit::initJoined() {
  childIds.clear();
  resistanceId = -1;
  assert(curChar() == '(');
  while (nextChar() != ')') {
    if (curChar() == 'S')
      isSeries = 1;
    else if (curChar() == 'P')
      isSeries = 0;
    else
      giveBirth();
  }
  if (isSeries) {
    weight = INF;
    for (int id : childIds) {
      if (weight > circuits[id].weight) {
        weight = circuits[id].weight;
      }
    }
  } else {
    weight = 0;
    for (int id : childIds) {
      weight += circuits[id].weight;
    }
  }
}
void Circuit::build() {
  if (curChar() == '*') {
    initResistance();
  } else {
    initJoined();
  }
}
void Circuit::putResistance(int64_t totalCost) {
  if (resistanceId >= 0) {
    resistances[resistanceId] = totalCost;
  } else if (isSeries) {
    int favouriteChild = childIds[0];
    for (int child : childIds) {
      if (circuits[child].weight < circuits[favouriteChild].weight) {
        favouriteChild = child;
      }
    }
    circuits[favouriteChild].putResistance(totalCost);
  } else {
    assert(totalCost % weight == 0);
    for (int child : childIds) {
      circuits[child].putResistance(totalCost / weight *
                                    circuits[child].weight);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int noTests;
  cin >> noTests;
  circuits.reserve(200003);
  while (noTests--) {
    int multiplier;
    cin >> multiplier;
    getline(cin, str);
    strPtr = 0;
    circuits.assign(1, {});
    resistances.clear();
    circuits[0].build();
    circuits[0].putResistance(multiplier * circuits[0].weight *
                              circuits[0].weight);
    cout << "REVOLTING ";
    for (int64_t resistance : resistances) {
      cout << resistance << ' ';
    }
    cout << '\n';
  }
  return 0;
}
