#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   int t, tot, type[N];   long long r, f[N];   vector<int> son[N];   template <class T>   inline void read(T &x) {     x = 0;     char ch = getchar(), w = 0;     while (!isdigit(ch)) w = ch ==  - , ch = getchar();     while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();     x = w ? -x : x;     return;   }   inline char getch() {     char c = getchar();     while (c ==    ) c = getchar();     return c;   }   int solve(int fa) {     char c = getch();     int now = ++tot;     type[now] = 0, son[now].clear();     if (c ==  * ) return f[now] = 1, now;     son[now].push_back(solve(now));     while (1) {       c = getch();       if (c ==  S )         type[now] = 1;       else if (c ==  P )         type[now] = 2;       else         break;       son[now].push_back(solve(now));     }     if (type[now] == 1) {       f[now] = 1e18;       for (auto &v : son[now]) f[now] = min(f[v], f[now]);     } else {       f[now] = 0;       for (auto &v : son[now]) f[now] += f[v];     }     return now;   }   void resolve(int now, long long r) {     if (type[now] == 0) {       printf( %lld  , r);       return;     }     if (type[now] == 1) {       int pos = 0;       long long minV = 1e18;       for (auto &k : son[now])         if (f[k] < minV) minV = f[k], pos = k;       for (auto &k : son[now]) resolve(k, pos == k ? r : 0);       return;     }     for (auto &k : son[now]) resolve(k, r);     return;   }   int main() {     read(t);     while (t--) {       read(r), tot = 0;       int root = solve(0);       printf( REVOLTING  );       resolve(root, r * f[root]);       printf(  n );     }     return 0;   }   