#include <bits/stdc++.h>   using namespace std;   using LL = long long;   const LL INF = 2000000000000000000L;   struct Event {     char c;     LL v;     int pos;   };   void Dfs(int pos, vector<vector<pair<LL, int>>>& edge, vector<bool>& parallel,            vector<LL>& ans) {     if (edge[pos].size() == 0) {       ans[pos] = 1;       return;     }     if (parallel[pos]) {       for (auto [vv, j] : edge[pos]) {         Dfs(j, edge, parallel, ans);       }     } else {       int j = 0;       for (int i = 0; i < edge[pos].size(); ++i) {         if (edge[pos][i].first < edge[pos][j].first) j = i;       }       Dfs(edge[pos][j].second, edge, parallel, ans);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int times;     cin >> times;     while (times--) {       int n;       cin >> n;       string ss;       getline(cin, ss);       string s;       for (char c : ss) {         if (c ==    ) continue;         s.push_back(c);       }       vector<vector<pair<LL, int>>> edge(s.size());       vector<bool> sign(s.size());       stack<Event> st;       for (int i = 0; i < s.size(); ++i) {         if (s[i] ==  ) ) {           vector<pair<LL, int>> x;           bool parallel = false;           int j = i;           while (true) {             Event e = st.top();             st.pop();             if (e.c ==  ( ) {               j = e.pos;               break;             }             if (e.c ==  P ) parallel = true;             if (e.c ==  S ) parallel = false;             if (e.c ==  * ) {               x.push_back({e.v, e.pos});             }           }           sign[j] = parallel;           for (int i = 0; i < x.size(); ++i) {             edge[j].push_back(x[i]);           }           if (parallel) {             LL ans = 0;             for (auto [a, b] : x) ans += a;             st.push({ * , ans, j});           } else {             LL ans = INF;             for (auto [a, b] : x) ans = min(ans, a);             st.push({ * , ans, j});           }         } else {           st.push({s[i], 1, i});         }       }       vector<LL> ans(s.size());       Dfs(0, edge, sign, ans);       cout <<  REVOLTING  ;       for (int i = 0; i < s.size(); ++i) {         if (s[i] ==  * ) cout << ans[i] * n * st.top().v <<    ;       }       cout <<   n ;     }     return 0;   }   