#include <bits/stdc++.h>
 using namespace std;
 long long mul(long long a, long long b, long long p = 1000000007) {
   return ((a  p) * (b  p))  p;
 }
 long long add(long long a, long long b, long long p = 1000000007) {
   return (a  p + b  p)  p;
 }
 void input(long long a[], long long sz) {
   for (long long i = 0; i < sz; i++) cin >> a[i];
 }
 void print(long long a[], long long sz) {
   for (long long i = 0; i < sz; i++) {
     if (i == sz - 1)
       cout << a[i] <<
 ;
     else
       cout << a[i] <<    ;
   }
 }
 long long maxr(long long a[], long long sz) {
   long long ma;
   for (long long i = 0; i < sz; i++) {
     if (i == 0)
       ma = a[i];
     else if (a[i] > ma)
       ma = a[i];
   }
   return ma;
 }
 long long minr(long long a[], long long sz) {
   long long mi;
   for (long long i = 0; i < sz; i++) {
     if (i == 0)
       mi = a[i];
     else if (a[i] < mi)
       mi = a[i];
   }
   return mi;
 }
 long long isprm(long long n) {
   if (n <= 1) return 0;
   if (n <= 3) return 1;
   if (n  2 == 0 || n  3 == 0) return 0;
   for (int i = 5; i * i <= n; i = i + 6)
     if (n  i == 0 || n  (i + 2) == 0) return 0;
   return 1;
 }
 long long power(long long x, long long y, long long p = 1000000007) {
   long long res = 1;
   x = x  p;
   while (y > 0) {
     if (y & 1) res = (res * x)  p;
     y = y >> 1;
     x = (x * x)  p;
   }
   return res;
 }
 long long modInverse(long long n, long long p = 1000000007) {
   return power(n, p - 2, p);
 }
 long long ncrMod(long long n, long long r, long long p = 1000000007) {
   if (r == 0) return 1;
   long long fac[n + 1];
   fac[0] = 1;
   for (long long i = 1; i <= n; i++) fac[i] = fac[i - 1] * i  p;
   return (fac[n] * modInverse(fac[r], p)  p * modInverse(fac[n - r], p)  p)
          p;
 }
 bool comp(const pair<int, int> &a, const pair<int, int> &b) {
   if (a.first == b.first) {
     return (a.second > b.second);
   }
   return (a.first < b.first);
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   ;
   int t;
   cin >> t;
   while (t--) {
     long long n, k;
     cin >> n >> k;
     long long q = n / k;
     long long r = n  k;
     if ((r  2 == 1 && k  2 == 0) || (r  2 == 1 && q == 1) || q == 0)
       cout <<  NO
 ;
     else {
       cout <<  YES
 ;
       if (r  2 == 0) {
         cout << q + r <<    ;
         for (long long i = 0; i < k - 1; i++) cout << q <<    ;
         cout <<
 ;
       } else {
         cout << q + r <<    ;
         for (long long i = 0; i < k - 1; i++) {
           if (i  2 == 0)
             cout << q - 1 <<    ;
           else
             cout << q + 1 <<    ;
         }
         cout <<
 ;
       }
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 5e5 + 20;
 struct edge {
   int v, l, r;
   edge() {}
   edge(int a, int b, int c) {
     v = a;
     l = b;
     r = c;
   }
 };
 struct nd {
   int no, lim, to;
   nd() {}
   nd(int a, int b, int c) {
     no = a;
     lim = b;
     to = c;
   }
 };
 bool operator<(const nd& a, const nd& b) {
   if (a.no != b.no) {
     return a.no > b.no;
   }
   if (a.lim != b.lim) {
     return a.lim > b.lim;
   }
   return a.to < b.to;
 }
 bool operator<(const edge& a, const edge& b) {
   if (a.l != b.l) {
     return a.l < b.l;
   }
   return a.r < b.r;
 }
 vector<edge> G[2 * maxn];
 int now[2 * maxn];
 int main() {
   int n, m, u, v, l, r;
   scanf( dd , &n, &m);
   for (int i = 0; i < m; i++) {
     scanf( dddd , &u, &v, &l, &r);
     if (l & 1) {
       if (r & 1) {
         G[u].push_back(edge(v + n, l + 1, r - 1));
         G[v].push_back(edge(u + n, l + 1, r - 1));
         G[u + n].push_back(edge(v, l, r - 2));
         G[v + n].push_back(edge(u, l, r - 2));
       } else {
         if (l + 1 < r) {
           G[u].push_back(edge(v + n, l + 1, r - 2));
           G[v].push_back(edge(u + n, l + 1, r - 2));
         }
         G[u + n].push_back(edge(v, l, r - 1));
         G[v + n].push_back(edge(u, l, r - 1));
       }
     } else {
       if (r & 1) {
         G[u].push_back(edge(v + n, l, r - 1));
         G[v].push_back(edge(u + n, l, r - 1));
         if (l + 1 < r) {
           G[u + n].push_back(edge(v, l + 1, r - 2));
           G[v + n].push_back(edge(u, l + 1, r - 2));
         }
       } else {
         G[u].push_back(edge(v + n, l, r - 2));
         G[v].push_back(edge(u + n, l, r - 2));
         G[u + n].push_back(edge(v, l + 1, r - 1));
         G[v + n].push_back(edge(u, l + 1, r - 1));
       }
     }
   }
   for (int i = 1; i <= n + n; i++) {
     sort(G[i].begin(), G[i].end());
   }
   priority_queue<nd> Q;
   Q.push(nd(0, 0, 1));
   int ans = 0x3f3f3f3f;
   nd t;
   while (!Q.empty()) {
     t = Q.top();
     int u = t.to, no = t.no, lim = t.lim;
     Q.pop();
     if (u == n || u == n * 2) {
       ans = min(ans, no);
     }
     for (int& i = now[u]; i < G[u].size(); i++) {
       if (lim < G[u][i].l) {
         break;
       }
       if (no <= G[u][i].r) {
         Q.push(nd(max(no + 1, G[u][i].l + 1), G[u][i].r + 1, G[u][i].v));
       }
     }
   }
   if (ans == 0x3f3f3f3f) {
     printf( -1
 );
   } else {
     printf( d
 , ans);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1000008;
 int n, m, k, d, i, j, e;
 int tmp[N], pos[N], p[N], c[N];
 char s[N];
 int main() {
   scanf( s d , s, &m);
   n = strlen(s);
   while (m--) {
     scanf( dd , &k, &d);
     for (i = 0; i < n; i++) {
       c[i] = (i + 1)  n;
       pos[i] = p[i] = i;
     }
     int t = 0;
     for (i = 0; i < d; i++)
       for (j = i; j < k; t++, j += d) p[t] = j;
     for (i = 0; i < n; ++i) {
       c[i] = p[c[i]];
     }
     for (e = n - k + 1; e; e >>= 1) {
       for (i = 0; i < n; ++i) tmp[i] = c[i];
       if (e & 1)
         for (i = 0; i < n; ++i) pos[i] = c[pos[i]];
       for (i = 0; i < n; ++i) c[i] = tmp[c[i]];
     }
     for (i = 0; i < n; ++i) tmp[(i + n - k + 1)  n] = s[pos[i]];
     for (i = 0; i < n; ++i) putchar(s[i] = (char)tmp[i]);
     putchar('
');
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m;
 vector<int> ke[1000010];
 bool cx[1000010], visited[1000010];
 void dfs(int u) {
   visited[u] = true;
   for (int v : ke[u])
     if (!visited[v]) dfs(v);
 }
 long long c2(int x) { return (1LL * x * (x - 1)) >> 1; }
 int main() {
   if (fopen( a.txt ,  r )) {
     freopen( a.txt ,  r , stdin);
   } else
     ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cin >> n >> m;
   int own = 0;
   for (int i = 1; i <= m; i++) {
     int u, v;
     cin >> u >> v;
     cx[u] = true;
     cx[v] = true;
     if (u != v) {
       ke[u].push_back(v);
       ke[v].push_back(u);
     } else
       own++;
   }
   int cnt = 0;
   for (int u = 1; u <= n; u++)
     if (cx[u] && !visited[u]) {
       dfs(u);
       cnt++;
     }
   if (cnt != 1) {
     cout << 0;
     exit(0);
   };
   long long res = 0;
   for (int i = 1; i <= n; i++) res += c2(int(ke[i].size()));
   res += c2(own);
   res += 1LL * own * (m - own);
   cout << res;
 }


#include <bits/stdc++.h>
 using namespace std;
 int get_point(int N) {
   int score[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
   if (N > 10) return 0;
   return score[N - 1];
 }
 int main() {
   int T;
   map<string, int> n_map;
   map<string, string> n_win;
   cin >> T;
   for (int i = 0; i < (T); ++i) {
     int N;
     cin >> N;
     for (int j = 0; j < (N); ++j) {
       string t_s;
       cin >> t_s;
       n_map[t_s] += get_point(j + 1);
       if (n_win[t_s] ==   )
         n_win[t_s] =  0000000000000000000000000000000000000000000000000000 ;
       n_win[t_s][j] += 1;
     }
   }
   map<string, int>::iterator it;
   int n_max1 = 0, n_max2 = 0;
   string n_ret1 =   , n_ret2 =   ;
   n_win[  ] =  0000000000000000000000000000000000000000000000000000 ;
   for (it = n_map.begin(); it != n_map.end(); it++) {
     if (n_max1 < (*it).second) {
       n_ret1 = (*it).first;
       n_max1 = (*it).second;
     }
     if (n_max1 == (*it).second && n_win[n_ret1] < n_win[(*it).first]) {
       n_ret1 = (*it).first;
       n_max1 = (*it).second;
     }
     if (n_win[n_ret2][0] < n_win[(*it).first][0]) {
       n_ret2 = (*it).first;
       n_max2 = (*it).second;
     }
     if (n_win[n_ret2][0] == n_win[(*it).first][0] && n_max2 < (*it).second) {
       n_ret2 = (*it).first;
       n_max2 = (*it).second;
     }
     if (n_win[n_ret2][0] == n_win[(*it).first][0] && n_max2 == (*it).second) {
       if (n_win[n_ret2] < n_win[(*it).first]) {
         n_ret2 = (*it).first;
         n_max2 = (*it).second;
       }
     }
   }
   cout << n_ret1 << endl;
   cout << n_ret2 << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 40;
 const int F = N / 2 + N  2;
 const int S = N - F;
 const long long N_MASKS = (1ll << N);
 const long long F_MASKS = (1ll << F);
 const long long S_MASKS = (1ll << S);
 double liquid;
 int n, f, s;
 long long adj[N];
 int firstSizes[F_MASKS];
 long long firstAvailables[F_MASKS];
 int secondSizes[S_MASKS];
 long long secondAvailables[S_MASKS];
 int maxPossible[S_MASKS];
 void readData() {
   cin >> n >> liquid;
   f = n / 2 + n  2;
   s = n - f;
   for (int i = 0; i < n; ++i) {
     for (int j = 0; j < n; ++j) {
       long long a;
       cin >> a;
       adj[i] |= (a << j);
     }
   }
 }
 void findCliques(int sta, int cur, int fin, long long mask, int size,
                  long long available, int* sizes, long long* availables) {
   if (cur == fin) {
     return;
   }
   findCliques(sta, cur + 1, fin, mask, size, available, sizes, availables);
   if ((1ll << cur) & available) {
     mask |= (1ll << cur);
     ++size;
     available &= adj[cur];
     sizes[mask >> sta] = size;
     availables[mask >> sta] = available;
     findCliques(sta, cur + 1, fin, mask, size, available, sizes, availables);
   }
 }
 int findPossibles(long long available) {
   if (maxPossible[available]) {
     return maxPossible[available];
   }
   if (available == 0) {
     return 0;
   }
   if (secondSizes[available]) {
     return maxPossible[available] = secondSizes[available];
   }
   for (int i = 0; i < s; ++i) {
     if (available & (1ll << i)) {
       maxPossible[available] =
           max(maxPossible[available], findPossibles(available & ~(1ll << i)));
     }
   }
   return maxPossible[available];
 }
 int findMaxClique() {
   findCliques(0, 0, f, 0, 0, (1ll << n) - 1, firstSizes, firstAvailables);
   findCliques(f, f, n, 0, 0, (1ll << n) - 1, secondSizes, secondAvailables);
   int res = findPossibles((1 << s) - 1);
   for (int mask = 0; mask < (1 << f); ++mask) {
     if (firstSizes[mask]) {
       res = max(res,
                 firstSizes[mask] + findPossibles(firstAvailables[mask] >> f));
     }
   }
   return res;
 }
 double solve() {
   int x = findMaxClique();
   return 0.5 * liquid * liquid * (x - 1.) / x;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cout << setprecision(20) << fixed;
   readData();
   cout << solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
 long long power(long long a, long long b) {
   long long res = 1;
   while (b) {
     if (b  2) res = (res * a)  5;
     b = b >> 1;
     a = (a * a)  5;
   }
   return res;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   long long i, n, t;
   cin >> n >> t;
   long long ans = 1e16;
   pair<long long, long long> p;
   for (i = 0; i < t; i++) {
     long long a, b;
     cin >> a >> b;
     if (b - a + 1 < ans) {
       ans = b - a + 1;
     }
   }
   cout << ans << '
';
   long long c = 0;
   for (i = 0; i < n; i++) {
     if (i  ans == 0) {
       c = 0;
       cout << c <<    ;
       c++;
     } else {
       cout << c <<    ;
       c++;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 200005;
 vector<int> lk[maxn];
 int fa[maxn], dep[maxn], a[maxn], b[maxn], n;
 void dfs(int now, int pre) {
   fa[now] = pre;
   dep[now] = dep[pre] + 1;
   for (auto p : lk[now])
     if (p != pre) dfs(p, now);
 }
 vector<int> cir;
 int rt, lp, lq;
 bool find_circle() {
   cir.clear();
   static bool vis[maxn];
   int p = 0;
   for (int i = 1; i <= n; i++)
     if (a[i] != b[i] && dep[i] > dep[p]) p = i;
   if (!p) return 1;
   for (int u = p; vis[u] = 1, cir.push_back(u), a[fa[u]] != b[fa[u]]; u = fa[u])
     ;
   int q = 0;
   for (int i = 1; i <= n; i++)
     if (a[i] != b[i] && !vis[i] && dep[i] > dep[q]) q = i;
   if (q) {
     reverse(cir.begin(), cir.end());
     for (int u = q; vis[u] = 1, cir.push_back(u), a[fa[u]] != b[fa[u]];
          u = fa[u])
       ;
   } else
     q = fa[cir.back()];
   for (int i = 1; i <= n; i++)
     if (a[i] != b[i] && !vis[i]) return 0;
   int u, v;
   for (u = p, v = q; u != v; u = fa[u])
     if (dep[u] < dep[v]) swap(u, v);
   rt = u;
   if (cir.size() != dep[p] + dep[q] - 2 * dep[rt]) return 0;
   lp = p, lq = q;
   return 1;
 }
 int main() {
   scanf( d , &n);
   for (int i = 1; i <= n; i++) scanf( d , &a[i]);
   for (int i = 1; i <= n; i++) scanf( d , &b[i]);
   for (int i = 1, u, v; i < n; i++) {
     scanf( dd , &u, &v);
     lk[u].push_back(v), lk[v].push_back(u);
   }
   int pa = find(a + 1, a + n + 1, 0) - a, pb = find(b + 1, b + n + 1, 0) - b;
   dep[0] = -1;
   dfs(pb, 0);
   for (int u = pa; u != pb; u = fa[u]) swap(a[u], a[fa[u]]);
   long long ans = dep[pa];
   if (!find_circle()) {
     printf( -1
 );
     return 0;
   }
   if (!cir.size()) {
     printf( 0 d
 , ans);
     return 0;
   }
   int gap = 0, len = cir.size();
   for (int i = 0; i < len; i++)
     if (b[cir[i]] == a[cir[0]]) gap = i;
   for (int i = 1; i < len; i++)
     if (b[cir[(i + gap)  len]] != a[cir[i]]) {
       printf( -1
 );
       return 0;
     }
   static bool vis[maxn];
   for (int i = pa; i; i = fa[i]) vis[i] = 1;
   if (vis[cir[0]] || vis[cir.back()]) {
     if (vis[cir.back()]) reverse(cir.begin(), cir.end()), gap = len - gap;
     int po = cir.size();
     for (int i = 0; i < cir.size(); i++)
       if (!vis[cir[i]]) {
         po = i;
         break;
       }
     ans = ans - po +
           min(po + gap * 1ll * (len + 1),
               abs((len - gap) * 1ll * (len + 1) - po));
   } else
     ans = (ans + min(gap, len - gap) * 1ll * (len + 1));
   for (; !vis[rt]; rt = fa[rt]) ans += 2;
   if (lp > lq) swap(lq, lp);
   printf( d d lld
 , lp, lq, ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 5010;
 struct Edge {
   int v, u, f, r, c;
   Edge() {}
   Edge(int v, int u, int f, int c, int r) : v(v), u(u), f(f), c(c), r(r) {}
 };
 const int inf = 1e9;
 const int C = 4000;
 int n, m, k, nflow, s, t, parent[N], number[N], a[N], b[N];
 int dist[N], pl[N];
 vector<Edge> g[N];
 queue<pair<int, int> > q;
 vector<int> ga, gb;
 void addEdge(int a, int b, int u, int c) {
   g[a].push_back(Edge(b, u, 0, c, g[b].size()));
   g[b].push_back(Edge(a, 0, 0, -c, g[a].size() - 1));
 }
 int MinCostFlow() {
   int flow = 0;
   int cost = 0;
   while (true) {
     for (int i = 1; i <= nflow; i++) dist[i] = inf;
     dist[s] = 0;
     q.push(make_pair(0, s));
     while (!q.empty()) {
       int v = (q.front()).second;
       int d = -(q.front()).first;
       q.pop();
       if (dist[v] != d) continue;
       if (d == inf) break;
       for (int i = 0; i < g[v].size(); i++)
         if (g[v][i].f < g[v][i].u && dist[g[v][i].v] > d + g[v][i].c) {
           dist[g[v][i].v] = d + g[v][i].c;
           q.push(make_pair(-dist[g[v][i].v], g[v][i].v));
           number[g[v][i].v] = i;
           parent[g[v][i].v] = v;
         }
     }
     if (dist[t] == inf) break;
     int v = t, addflow = 1e9;
     while (v != s) {
       int u = parent[v];
       addflow = min(addflow, g[u][number[v]].u - g[u][number[v]].f);
       v = u;
     }
     v = t;
     while (v != s) {
       int u = parent[v];
       cost += addflow * g[u][number[v]].c;
       g[u][number[v]].f += addflow;
       g[v][g[u][number[v]].r].f -= addflow;
       v = u;
     }
     flow += addflow;
   }
   return cost;
 }
 int main() {
   scanf( ddd , &n, &m, &k);
   for (int i = 1; i <= n; i++) scanf( d , &a[i]);
   for (int i = 1; i <= n; i++) scanf( d , &b[i]);
   s = n + 3;
   t = n + 4;
   for (int i = 1; i <= n; i++) {
     addEdge(n + 1, i, 1, -a[i]);
     addEdge(n + 2, i, 1, -b[i]);
   }
   addEdge(s, n + 1, m, 0);
   addEdge(s, n + 2, k, 0);
   for (int i = 1; i <= n; i++) {
     addEdge(i, t, 1, 0);
   }
   nflow = n + 4;
   int ans = -MinCostFlow();
   cout << ans << endl;
   for (int j = 0; j < g[n + 1].size(); j++) {
     int v = g[n + 1][j].v;
     if (v >= 1 && v <= n && g[n + 1][j].f == 1) {
       ga.push_back(v);
     }
   }
   for (int j = 0; j < g[n + 2].size(); j++) {
     int v = g[n + 2][j].v;
     if (v >= 1 && v <= n && g[n + 2][j].f == 1) {
       gb.push_back(v);
     }
   }
   for (int i = 0; i < ga.size(); i++) cout << ga[i] <<    ;
   cout << endl;
   for (int i = 0; i < gb.size(); i++) cout << gb[i] <<    ;
   cout << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 2e5 + 5;
 int n;
 double a[N];
 double max_poor(double x) {
   int i;
   double pre, mpre, ret = 0;
   pre = mpre = 0;
   for (i = 0; i < n; i++) {
     pre += a[i] - x;
     ret = max(ret, abs(pre - mpre));
     mpre = min(mpre, pre);
   }
   pre = mpre = 0;
   for (i = 0; i < n; i++) {
     pre += a[i] - x;
     ret = max(ret, abs(pre - mpre));
     mpre = max(mpre, pre);
   }
   return ret;
 }
 int main() {
   cin.tie(0);
   ios::sync_with_stdio(0);
   int i;
   double l = 0.0, h = 0.0, m1, m2;
   cin >> n;
   for (i = 0; i < n; h = max(h, abs(a[i])), i++) cin >> a[i];
   l = -h;
   for (i = 0; i < 300; i++) {
     m1 = l + (h - l) / 3;
     m2 = h - (h - l) / 3;
     if (max_poor(m1) > max_poor(m2))
       l = m1;
     else
       h = m2;
   }
   printf( .17f
 , max_poor(l));
   return 0;
 }


#include <bits/stdc++.h>
 const long long MOD = 1000000007;
 const int MAX = 1e9 + 7;
 const int MIN = -1e9 + 7;
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   long long b, g;
   cin >> b >> g;
   long long n;
   cin >> n;
   if (b >= n && g >= n) {
     cout << n + 1;
   } else if (b + g == n) {
     cout << 1;
   } else if (b >= n || g >= n) {
     cout << min(b, g) + 1;
   } else {
     cout << b + g - n + 1;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXN = int(5e4) + 100;
 const int MOD = int(360);
 const int oo = INT_MAX;
 const long double PI = acos(-1.0);
 const long double EPS = 1e-9;
 struct pt {
   long double x, y;
   pt() {}
   pt(long double x, long double y) : x(x), y(y) {}
 };
 inline long double x(pt P) { return P.x; }
 inline long double y(pt P) { return P.y; }
 istream& operator>>(istream& in, pt& p) {
   long double x, y;
   in >> x >> y;
   p = pt(x, y);
   return in;
 }
 ostream& operator<<(ostream& out, const pt& p) {
   out <<  (  << double(p.x) <<  ,   << double(p.y) <<  ) ;
   return out;
 }
 pt operator+(const pt& A, const pt& B) { return pt(x(A) + x(B), y(A) + y(B)); }
 pt operator-(const pt& A, const pt& B) { return pt(x(A) - x(B), y(A) - y(B)); }
 pt operator*(const pt& A, const pt& B) {
   return pt(x(A) * x(B) - y(A) * y(B), x(A) * y(B) + y(A) * x(B));
 }
 pt operator*(const pt& A, const long double& B) {
   return pt(x(A) * B, y(A) * B);
 }
 pt operator*(const long double& B, const pt& A) {
   return pt(x(A) * B, y(A) * B);
 }
 pt operator/(const pt& A, const long double& B) {
   return pt(x(A) / B, y(A) / B);
 }
 inline long double norm(pt A) { return x(A) * x(A) + y(A) * y(A); }
 inline long double abs(pt A) { return sqrt(norm(A)); }
 inline long double cross(pt A, pt B) { return x(A) * y(B) - y(A) * x(B); }
 inline long double dot(pt A, pt B) { return x(A) * x(B) + y(A) * y(B); }
 inline bool same(long double a, long double b) {
   return a + EPS > b && b + EPS > a;
 }
 inline bool samePt(pt A, pt B) { return same(x(A), x(B)) && same(y(A), y(B)); }
 inline long double dist(pt A, pt B) { return abs(B - A); }
 inline pt rotcw(pt p) { return p * pt(0, -1); }
 inline bool segContains(pt X, pt A, pt B) {
   if (samePt(X, A) || samePt(X, B)) return 1;
   if (!same(0, cross(A - X, B - X))) return 0;
   return (dot(A - X, B - X) < EPS);
 }
 pt linesIntersection(pt A, pt B, pt C, pt D) {
   long double x = cross(C, D - C) - cross(A, D - C);
   x /= cross(B - A, D - C);
   return A + x * (B - A);
 }
 double signedArea(const vector<pt>& P) {
   double result = 0.0;
   for (int i = 0; i < (int)P.size() - 1; i++) result += cross(P[i], P[i + 1]);
   return result / 2.0;
 }
 vector<pt> reorganize(vector<pt>& P) {
   int n = int(P.size());
   vector<pt> R(n);
   if (P.size() == 1) {
     R[0] = P[0];
     return R;
   }
   if (signedArea(P) > EPS) {
     reverse(P.begin(), P.end());
   }
   int s = 0;
   for (int i = 1; i < n; ++i) {
     if (x(P[s]) > x(P[i]) || (x(P[s]) == x(P[i]) && y(P[s]) > y(P[i]))) {
       s = i;
     }
   }
   R[0] = P[s];
   for (int i = (s + 1)  n, j = 1; i != s; i = (i + 1)  n, ++j) {
     if (samePt(P[i], P[(i - 1 + n)  n])) {
       j--;
       continue;
     }
     R[j] = P[i];
   }
   R[n - 1] = R[0];
   return R;
 }
 vector<pt> convexPolygonSum(vector<pt>& P, vector<pt>& Q) {
   P = reorganize(P);
   Q = reorganize(Q);
   int n = int(P.size()), m = int(Q.size());
   vector<pt> R(n + m - 1);
   R[0] = (P[0] + Q[0]);
   int i = 1, j = 1, k = 1;
   for (; i < n && j < m; ++k) {
     if (cross(P[i] - P[i - 1], Q[j] - Q[j - 1]) < -EPS) {
       R[k] = R[k - 1] + (P[i] - P[i - 1]);
       ++i;
     } else {
       R[k] = R[k - 1] + (Q[j] - Q[j - 1]);
       ++j;
     }
   }
   while (i < n) {
     R[k] = R[k - 1] + (P[i] - P[i - 1]);
     ++i;
     ++k;
   }
   while (j < m) {
     R[k] = R[k - 1] + (Q[j] - Q[j - 1]);
     ++j;
     ++k;
   }
   vector<pt> T;
   T.push_back(R[0]);
   for (int i = 1; i + 1 < int(R.size()); ++i) {
     if (same(cross(R[i] - R[i - 1], R[i + 1] - R[i - 1]), 0.0)) continue;
     T.push_back(R[i]);
   }
   T.push_back(T[0]);
   return T;
 }
 int inConvexPolygon(pt X, long double mnx, long double mxx, vector<pt>& P) {
   if (x(X) < mnx || x(X) > mxx) return -1;
   int lo = 1, hi = int(P.size()) - 1, mi;
   while (lo <= hi) {
     mi = (lo + hi) / 2;
     if (cross(P[mi] - P[0], X - P[0]) < -EPS) {
       lo = mi + 1;
     } else {
       hi = mi - 1;
     }
   }
   lo = hi;
   if (hi == -1) return -1;
   long double c = cross(X - P[lo], X - P[lo + 1]);
   if (same(c, 0.0)) return (segContains(X, P[lo], P[lo + 1]) ? 0 : -1);
   if (c > EPS) return -1;
   return 1;
 }
 int l, n, m, q;
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   while (cin >> l) {
     vector<pt> P1(l + 1);
     for (int i = 0; i < l; ++i) {
       cin >> P1[i];
     }
     cin >> n;
     vector<pt> P2(n + 1);
     for (int i = 0; i < n; ++i) {
       cin >> P2[i];
     }
     cin >> m;
     vector<pt> P3(m + 1);
     for (int i = 0; i < m; ++i) {
       cin >> P3[i];
     }
     P1[l] = P1[0];
     P2[n] = P2[0];
     P3[m] = P3[0];
     vector<pt> P = convexPolygonSum(P2, P3);
     P = convexPolygonSum(P1, P);
     long double mnx = x(P[0]);
     long double mxx = -oo;
     for (int i = 0; i < int(P.size()); ++i) {
       mxx = max(mxx, x(P[i]));
     }
     cin >> q;
     for (int i = 0; i < q; ++i) {
       pt cur;
       cin >> cur;
       cur = 3.0 * cur;
       if (inConvexPolygon(cur, mnx, mxx, P) >= 0) {
         cout <<  YES
 ;
       } else {
         cout <<  NO
 ;
       }
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, k = 0;
   string home;
   cin >> n;
   cin >> home;
   for (int i = 0; i < n; i++) {
     string now;
     cin >> now;
     now = now.substr(5, 3);
     if (now == home) k++;
   }
   if (k == n - k)
     cout <<  home ;
   else
     cout <<  contest ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename T>
 using min_heap = priority_queue<T, vector<T>, greater<T>>;
 struct RangeIncrement {
   vector<long long> tree, lazy;
   RangeIncrement(int n) : tree(n << 2), lazy(n << 2) {}
   void refresh(int i, int l, int r) {
     if (lazy[i] != 0) {
       tree[i] += lazy[i] * (r - l + 1);
       if (l < r) {
         int lc = i << 1, rc = (i << 1) + 1;
         lazy[lc] += lazy[i];
         lazy[rc] += lazy[i];
       }
       lazy[i] = 0;
     }
   }
   void update(int i, int l, int r, int ul, int ur, long long x) {
     refresh(i, l, r);
     if (r < ul || l > ur) {
       return;
     } else if (ul <= l && r <= ur) {
       lazy[i] += x;
       refresh(i, l, r);
     } else {
       int m = l + r >> 1;
       int lc = i << 1, rc = (i << 1) + 1;
       update(lc, l, m, ul, ur, x);
       update(rc, m + 1, r, ul, ur, x);
       tree[i] = tree[lc] + tree[rc];
     }
   }
   long long query(int i, int l, int r, int ql, int qr) {
     refresh(i, l, r);
     if (r < ql || l > qr) {
       return 0;
     } else if (ql <= l && r <= qr) {
       return tree[i];
     } else {
       int m = l + r >> 1;
       int lc = i << 1, rc = (i << 1) + 1;
       return query(lc, l, m, ql, qr) + query(rc, m + 1, r, ql, qr);
     }
   }
 };
 template <class T>
 struct DisjointRanges {
   struct Range {
     int l, r;
     T x;
     Range(int l, const pair<int, T>& p) : l(l), r(p.first), x(p.second) {}
   };
   map<int, pair<int, T>> s;
   vector<Range> update(int l, int r, T x) {
     vector<Range> bye;
     auto last = s.upper_bound(r);
     if (last != s.begin()) {
       auto it = prev(last);
       if (it->second.first > r) {
         last = s.emplace_hint(last, r + 1, it->second);
         it->second.first = r;
       }
     }
     auto first = s.lower_bound(l);
     if (first != s.begin()) {
       auto it = prev(first);
       if (it->second.first >= l) {
         bye.emplace_back(l, it->second);
         it->second.first = l - 1;
       }
     }
     while (first != last) {
       bye.emplace_back(first->first, first->second);
       first = s.erase(first);
     }
     s.emplace_hint(last, l, make_pair(r, x));
     return bye;
   }
 };
 int main() {
   int n, m;
   scanf( d d , &n, &m);
   RangeIncrement ri(n);
   DisjointRanges<int> dr;
   for (int i = 1; i <= n; i++) {
     dr.update(i, i, i);
   }
   while (m--) {
     int o, l, r, x;
     scanf( d d d , &o, &l, &r);
     switch (o) {
       case 1: {
         scanf( d , &x);
         auto v = dr.update(l, r, x);
         for (auto it : v) {
           ri.update(1, 1, n, it.l, it.r, abs(x - it.x));
         }
         break;
       }
       case 2: {
         printf( lld
 , ri.query(1, 1, n, l, r));
         break;
       }
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int cnt[100100];
 int R[100100];
 int n;
 long long power(long long a, long long b) {
   long long res = 1;
   while (b) {
     if (b & 1) res = (res * a)  1000000007;
     a = (a * a)  1000000007;
     b >>= 1;
   }
   return res;
 }
 int main() {
   memset(cnt, 0, sizeof(cnt));
   scanf( d , &n);
   int maxA = 0;
   for (int i = 1; i <= n; i++) {
     int tmp;
     scanf( d , &tmp);
     cnt[tmp]++;
     maxA = max(maxA, tmp);
   }
   for (int i = maxA; i >= 1; i--) cnt[i] += cnt[i + 1];
   long long ans = 0;
   for (int i = 1; i <= maxA; i++) {
     int tot = 0;
     for (int j = 1; j * j <= i; j++) {
       if (i  j == 0) {
         R[tot++] = j;
         if (j * j != i) {
           R[tot++] = i / j;
         }
       }
     }
     sort(R, R + tot);
     long long tmp =
         (power(tot, cnt[R[tot - 1]]) -
          power(tot - 1, cnt[R[tot - 1]])  1000000007 + 1000000007)
         1000000007;
     for (int j = 0; j < tot - 1; j++)
       tmp = (tmp * power(j + 1, cnt[R[j]] - cnt[R[j + 1]]))  1000000007;
     ans = (ans + tmp)  1000000007;
   }
   printf( extra
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 500100;
 const int maxp = 40;
 int n, q;
 double d[maxn][maxp];
 int p[maxn];
 void upd(int v, int k, double x) {
   while (v && k < maxp) {
     double a = d[v][k];
     d[v][k] *= x;
     x = (d[v][k] + 1) / (a + 1);
     v = p[v];
     k++;
   }
 }
 int main() {
   ios_base::sync_with_stdio(0);
   for (int i = 0; i < maxn; i++)
     for (int j = 0; j < maxp; j++) d[i][j] = 1;
   cin >> q;
   n = 1;
   for (int i = 0; i < q; i++) {
     int qtype, v;
     cin >> qtype >> v;
     if (qtype == 1) {
       p[++n] = v;
       upd(n, 0, 0);
     } else {
       double ans = 0;
       for (int j = 1; j < maxp; j++) ans += (1 - d[v][j]);
       cout << fixed << setprecision(10) << ans << '
';
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 using ll = long long;
 const ll INF = 1e14 + 7;
 using vi = vector<int>;
 using pii = pair<int, int>;
 using pli = pair<ll, int>;
 int ask(int i, int j) {
   cout <<  ?   << i <<     << j << endl;
   int ans;
   cin >> ans;
   return ans;
 }
 int main() {
   int n;
   cin >> n;
   vi ans(n + 4), curr(n + 4);
   curr[0] = ask(1, n);
   curr[1] = ask(2, n);
   ans[1] = curr[0] - curr[1];
   for (int i = 2; i <= n - 1; i++) {
     curr[i] = ask(i - 1, i);
     ans[i] = curr[i] - ans[i - 1];
   }
   ans[n] = curr[0];
   for (int i = 1; i < n; i++) {
     ans[n] -= ans[i];
   }
   cout <<  ! ;
   for (int i = 1; i <= n; i++) {
     cout <<     << ans[i];
   }
   cout << endl;
   fflush(stdout);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int a[200005];
 int b[200005];
 bool f[200005];
 int main() {
   int q, n;
   cin >> q;
   while (q--) {
     cin >> n;
     for (int i = 1; i <= n; i++) {
       cin >> a[i];
       b[i] = 1;
       f[i] = 0;
     }
     for (int i = 1; i <= n; i++) {
       int j = i;
       if (f[i] == 1) continue;
       f[i] = 1;
       int ctr = 1;
       while (a[j] != i) {
         ctr++;
         f[j] = 1;
         j = a[j];
       }
       j = i;
       while (a[j] != i) {
         b[j] = ctr;
         j = a[j];
       }
     }
     for (int i = 1; i <= n; i++) cout << b[i] <<    ;
     cout <<
 ;
   }
 }


#include <bits/stdc++.h>
 inline int readChar();
 template <class T = int>
 inline T readInt();
 template <class T>
 inline void writeInt(T x, char end = 0);
 inline void writeChar(int x);
 inline void writeWord(const char* s);
 static const int buf_size = 4096;
 inline int getChar() {
   static char buf[buf_size];
   static int len = 0, pos = 0;
   if (pos == len) pos = 0, len = fread(buf, 1, buf_size, stdin);
   if (pos == len) return -1;
   return buf[pos++];
 }
 inline int readChar() {
   int c = getChar();
   while (c <= 32) c = getChar();
   return c;
 }
 template <class T>
 inline T readInt() {
   int s = 1, c = readChar();
   T x = 0;
   if (c == '-') s = -1, c = getChar();
   while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getChar();
   return s == 1 ? x : -x;
 }
 static int write_pos = 0;
 static char write_buf[buf_size];
 inline void writeChar(int x) {
   if (write_pos == buf_size)
     fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
   write_buf[write_pos++] = x;
 }
 template <class T>
 inline void writeInt(T x, char end) {
   if (x < 0) writeChar('-'), x = -x;
   char s[24];
   int n = 0;
   while (x || !n) s[n++] = '0' + x  10, x /= 10;
   while (n--) writeChar(s[n]);
   if (end) writeChar(end);
 }
 inline void writeWord(const char* s) {
   while (*s) writeChar(*s++);
 }
 struct Flusher {
   ~Flusher() {
     if (write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
   }
 } flusher;
 using namespace std;
 struct static_graph {
   int colors[500000];
   int firstv[500000];
   set<int> pool;
   static const int N = 500000;
   static const int M = 900000;
   struct edge {
     int v;
     edge* next;
   } edges[M];
   int nedges;
   struct node {
     vector<int>* ice;
     int prev_colors;
     bool depth_use;
     edge* firstedge;
     inline void init() { firstedge = NULL; };
     inline edge* add_edge(edge* e) {
       e->next = firstedge;
       firstedge = e;
       return firstedge;
     };
   } nodes[N];
   int nnodes;
   static_graph() { nnodes = 0, nedges = 0; };
   inline node& new_node() {
     node& r = nodes[nnodes++];
     return r;
   }
   inline edge* new_edge() { return &(edges[nedges++]); };
   inline edge* add_edge(int a, int b) {
     edge* e = new_edge();
     e->v = b;
     return nodes[a].add_edge(e);
   };
   inline void add_bi_edge(int a, int b) {
     add_edge(a, b);
     add_edge(b, a);
   };
   void depth_go(int index, int prev) {
     node& cur = nodes[index];
     if (cur.depth_use++) return;
     for (int x : (*cur.ice))
       if (colors[x]) pool.erase(colors[x]);
     for (int x : (*cur.ice))
       if (!colors[x]) {
         colors[x] = (*pool.upper_bound(0));
         firstv[x] = index;
         pool.erase(colors[x]);
       }
     for (int x : (*cur.ice)) pool.insert(colors[x]);
     for (edge* e = cur.firstedge; e; e = e->next) {
       depth_go(e->v, index);
     };
   };
   void depth_run(int first) {
     chrono::time_point<chrono::high_resolution_clock> start, end;
     start = std::chrono::high_resolution_clock::now();
     for (int i = 0; i < nnodes; i++) {
       node& cur = nodes[i];
       cur.depth_use = false;
     };
     depth_go(first, -1);
   };
   vector<node*> depth_to_wide(int first) {}
   void read_graph(istream* f){};
 };
 static_graph g;
 int main() {
   istream& f = cin;
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   chrono::time_point<chrono::high_resolution_clock> start, end;
   start = std::chrono::high_resolution_clock::now();
   int n, m, c, x = 0;
   n = readInt<int>();
   m = readInt<int>();
   for (int i = 0; i < n; i++) {
     c = readInt<int>();
     static_graph::node& cur = g.new_node();
     cur.ice = new vector<int>();
     cur.ice->resize(c);
     cur.prev_colors = 0;
     for (int t = 0; t < c; t++) {
       x = readInt<int>();
       (*cur.ice)[t] = x - 1;
     };
     sort((*cur.ice).begin(), (*cur.ice).end());
     ;
   };
   for (int i = 0; i < n - 1; i++) {
     int a, b;
     a = readInt<int>(), b = readInt<int>();
     g.add_bi_edge(a - 1, b - 1);
   };
   for (int i = 0; i < m; i++) g.colors[i] = 0;
   for (int i = 0; i < m; i++) g.pool.insert(i + 1);
   g.depth_run(0);
   int mx = 1;
   for (int i = 0; i < m; i++) {
     mx = max(mx, g.colors[i]);
     if (!g.colors[i]) g.colors[i] = 1;
   }
   cout << mx << endl;
   for (int i = 0; i < m; i++) cout << g.colors[i] <<    ;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long pw(long long a, long long b) {
   if (b == 0) return 1;
   if (b  2 == 1)
     return (a * pw(a * a, b / 2));
   else
     return (1 * pw(a * a, b / 2));
 }
 void solve() {
   long long n, k;
   cin >> n >> k;
   long long a[n], b[k];
   for (int i = 0; i < n; i++) cin >> a[i];
   sort(a, a + n);
   int n1 = 0;
   for (int i = 0; i < k; i++) {
     cin >> b[i];
     if (b[i] == 1) n1++;
   }
   sort(b, b + k);
   long long ans = 0;
   for (int i = 0; i < n1; i++) ans += (a[n - 1 - i] * 2);
   long long st = 0, en = n - 1 - n1;
   for (long long i = k - 1; i >= n1; i--) {
     if (b[i] == 1) {
       ans += (a[en] * 2);
       en--;
     } else {
       ans += a[en];
       b[i]--;
       en--;
       ans += a[st];
       st += b[i];
     }
   }
   cout << ans << endl;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   long long t = 1;
   cin >> t;
   while (t--) {
     solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct node {
   long long lvl1, lvl2, id;
 };
 node t[500005];
 bool cmp(struct node x, struct node y) {
   if (x.lvl1 < y.lvl1)
     return true;
   else
     return false;
 }
 vector<node> sh;
 vector<long long> adj[500005];
 long long vis[500005], lvl1[500005], lvl2[500005];
 void bfs1(long long n = 1) {
   queue<long long> q;
   q.push(n);
   vis[n] = 1;
   lvl1[n] = 0;
   while (!q.empty()) {
     long long x = q.front();
     q.pop();
     for (auto &cv : adj[x]) {
       if (vis[cv]) continue;
       q.push(cv);
       vis[cv] = 1;
       lvl1[cv] = lvl1[x] + 1;
     }
   }
 }
 void bfs2(long long n) {
   queue<long long> q;
   q.push(n);
   vis[n] = 1;
   lvl2[n] = 0;
   while (!q.empty()) {
     long long x = q.front();
     q.pop();
     for (auto &cv : adj[x]) {
       if (vis[cv]) continue;
       q.push(cv);
       vis[cv] = 1;
       lvl2[cv] = lvl2[x] + 1;
     }
   }
 }
 node combine(node x, node y) {
   if (x.lvl2 > y.lvl2)
     return x;
   else
     return y;
 }
 void build(long long n) {
   for (long long i = n - 1; i > 0; --i)
     t[i] = combine(t[i << 1], t[i << 1 | 1]);
 }
 node query(long long l, long long r, long long n) {
   node res;
   res.lvl2 = res.lvl1 = res.id = 0;
   for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
     if (l & 1) res = (combine(t[l++], res));
     if (r & 1) res = combine(t[--r], res);
   }
   return res;
 }
 long long arr[500005];
 int32_t main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   long long i, j, k, l, m, n, x, y;
   cin >> n >> m >> k;
   for (i = 0; i < k; i++) {
     cin >> arr[i];
   }
   for (i = 0; i < m; i++) {
     cin >> x;
     cin >> y;
     adj[x].push_back(y);
     adj[y].push_back(x);
   }
   bfs1();
   memset(vis, 0, sizeof vis);
   bfs2(n);
   for (i = 0; i < k; i++) {
     node temp;
     temp.id = arr[i];
     temp.lvl1 = lvl1[arr[i]];
     temp.lvl2 = lvl2[arr[i]];
     sh.push_back(temp);
   }
   sort(sh.begin(), sh.end(), cmp);
   for (i = 0; i < sh.size(); i++) {
     t[i + k].lvl1 = sh[i].lvl1;
     t[i + k].lvl2 = sh[i].lvl2;
     t[i + k].id = sh[i].id;
   }
   build(k);
   long long ans = 0;
   for (i = 0; i + 1 < sh.size(); i++) {
     long long temp;
     temp = sh[i].lvl1;
     temp++;
     temp += query(i + 1, sh.size(), sh.size()).lvl2;
     ans = max(ans, temp);
   }
   cout << min(lvl2[1], ans) << endl;
   return 0;
 }


#include <bits/stdc++.h>
 #pragma warning(disable : 4786)
 #pragma comment(linker,  /STACK:102400000,102400000 )
 using namespace std;
 const double eps = 1e-8;
 const double PI = acos(-1.0);
 const int MAXN = 200005;
 const int mod = 1000000007;
 const long long llinf = (long long)(1e18) + 500;
 const int inf = 0x3f3f3f3f;
 int x[1005];
 double y[1005];
 int main() {
   int i, j, k, m;
   int n, r;
   scanf( dd , &n, &r);
   for (i = 1; i <= n; i++) {
     scanf( d , x + i);
     y[i] = r * 1.0;
   }
   for (i = 2; i <= n; i++) {
     for (j = i - 1; j >= 1; j--) {
       int dx = abs(x[i] - x[j]);
       if (dx > 2 * r) continue;
       y[i] = max(y[i], y[j] + sqrt(4 * r * r * 1.0 - dx * 1.0 * dx));
     }
   }
   for (i = 1; i <= n; i++) {
     printf( .10lfc , y[i], i == n ? '
' : ' ');
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void solve() {
   int y, b, r;
   cin >> y >> b >> r;
   while (1) {
     if (r - 1 <= b && r - 2 <= y) {
       break;
     }
     --r;
   }
   cout << 3 * r - 3;
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   string n;
   cin >> n;
   long long even = 0;
   long long odd = 0;
   long long len = n.length();
   long long aeven = 0;
   long long aodd = 0;
   long long beven = 0;
   long long bodd = 0;
   for (int i = 0; i < len; i++) {
     if (n[i] == 'a') {
       if (i  2 == 1) {
         aodd++;
         odd += aodd;
         even += aeven;
       } else {
         aeven++;
         odd += aeven;
         even += aodd;
       }
     } else {
       if (i  2 == 1) {
         bodd++;
         odd += bodd;
         even += beven;
       } else {
         beven++;
         odd += beven;
         even += bodd;
       }
     }
   }
   cout << even <<     << odd << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int const N = 100000;
 long long a[N + 1];
 long long f[N * 3];
 inline int lc(int root) { return root << 1; }
 inline int rc(int root) { return (root << 1) | 1; }
 void build(int root, int l, int r) {
   f[root] = -1;
   if (l == r) {
     f[root] = a[l];
     return;
   }
   int mid = (l + r) >> 1;
   build(lc(root), l, mid);
   build(rc(root), mid + 1, r);
   if (f[lc(root)] == f[rc(root)]) {
     f[root] = f[lc(root)];
   }
 }
 void update(int root, int l, int r, int fi, int la, long long val) {
   if (fi == l && la == r) {
     f[root] = val;
     return;
   }
   int mid = (l + r) >> 1;
   f[root] = -1;
   if (fi > mid) {
     update(rc(root), mid + 1, r, fi, la, val);
   } else if (la <= mid) {
     update(lc(root), l, mid, fi, la, val);
   } else {
     update(lc(root), l, mid, fi, mid, val);
     update(rc(root), mid + 1, r, mid + 1, la, val);
   }
   if (f[lc(root)] == f[rc(root)]) {
     f[root] = f[lc(root)];
   }
 }
 long long query(int root, int l, int r, int fi, int la) {
   if (f[root] != -1) {
     return f[root];
   }
   int mid = (l + r) >> 1;
   if (fi > mid) {
     return query(rc(root), mid + 1, r, fi, la);
   } else if (la <= mid) {
     return query(lc(root), l, mid, fi, la);
   } else {
     return max(query(lc(root), l, mid, fi, mid),
                query(rc(root), mid + 1, r, mid + 1, la));
   }
 }
 void work() {
   int n;
   int m;
   long long w, h;
   long long res;
   scanf( d , &n);
   for (int i = 1; i <= n; ++i) {
     scanf( extra , &a[i]);
   }
   build(1, 1, n);
   scanf( d , &m);
   while (m--) {
     scanf( extraextra , &w, &h);
     res = query(1, 1, n, 1, w);
     printf( extra
 , res);
     update(1, 1, n, 1, w, res + h);
   }
 }
 int main() {
   work();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 map<long long int, int> mp;
 int main() {
   long long int b, q, l, m, t;
   scanf( lldlldlldlld , &b, &q, &l, &m);
   for (int i = 0; i < m; i++) {
     scanf( lld , &t);
     mp[t] = 1;
   }
   if (b < -l || b > l) {
     printf( 0
 );
     return 0;
   }
   if (b == 0) {
     if (mp[0])
       printf( 0
 );
     else
       printf( inf
 );
     return 0;
   } else if (q == 0) {
     if (mp[b] && mp[0])
       printf( 0
 );
     else if (!mp[b] && mp[0])
       printf( 1
 );
     else
       printf( inf
 );
     return 0;
   } else if (q == 1) {
     if (mp[b])
       printf( 0
 );
     else
       printf( inf
 );
     return 0;
   } else if (q == -1) {
     if (mp[b] && mp[-b])
       printf( 0
 );
     else
       printf( inf
 );
     return 0;
   } else {
     long long int cont = 0;
     while (b <= l && b >= -l) {
       if (!mp[b]) cont++;
       b *= q;
     }
     printf( lld
 , cont);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(0);
   string a, c;
   int b, d, p;
   int pos[110];
   p = 0;
   cin >> b >> d;
   cin >> a;
   cin >> c;
   int t = 0, la, lc;
   la = a.length();
   lc = c.length();
   int k = 0;
   for (int i = 0; i < lc; i++) {
     k = 0;
     for (int j = 0; j < la; j++)
       if (a[j] == c[(i + k)  lc]) k++;
     pos[i] = k;
   }
   int sum = 0;
   int j = 0;
   for (int i = 0; i < b; i++) {
     sum += pos[j];
     j = (j + pos[j])  lc;
   }
   sum /= lc;
   p = sum / d;
   cout << p << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m, a, b;
 set<pair<int, int> > s;
 set<int> sc;
 vector<int> ans;
 int main() {
   cin >> n >> m;
   for (int i = 1; i <= m; ++i) {
     cin >> a >> b;
     s.insert(make_pair(min(a, b), max(a, b)));
   }
   for (int i = 1; i <= n; ++i) {
     sc.insert(i);
   }
   for (int i = 1; i <= n; ++i) {
     if (sc.find(i) != sc.end()) {
       int cur = 0;
       queue<int> q;
       q.push(i);
       sc.erase(i);
       while (!q.empty()) {
         cur++;
         int v = q.front();
         q.pop();
         set<int>::iterator it;
         set<int> c = sc;
         for (it = c.begin(); it != c.end(); it++) {
           int to = *it;
           if (s.find(make_pair(min(v, to), max(v, to))) == s.end()) {
             q.push(to);
             sc.erase(to);
           }
         }
       }
       ans.push_back(cur);
     }
   }
   sort(ans.begin(), ans.end());
   cout << (int)ans.size() << endl;
   for (int i = 0; i < (int)ans.size(); ++i) {
     cout << ans[i] << ' ';
   }
   cout << endl;
   return 0;
 }


#include <bits/stdc++.h>
 #pragma comment(linker,  /STACK:10000000 )
 using namespace std;
 template <typename T>
 inline T abs(T a) {
   return ((a < 0) ? -a : a);
 }
 template <typename T>
 inline T sqr(T a) {
   return a * a;
 }
 const int INF = (int)1E9 + 7;
 const long double EPS = 1E-9;
 const long double PI = 3.1415926535897932384626433832795;
 const int NMAX = 200 * 1000;
 int a[NMAX], sza;
 int t[NMAX * 4], cnt[NMAX * 4];
 long long sum[NMAX * 4][5];
 char buf[300];
 void upd(int pos, int idx, int lf, int rg) {
   if (lf == rg) {
     t[idx] ^= 1;
     memset(sum[idx], 0, sizeof sum[idx]);
     sum[idx][0] = t[idx] * 1LL * a[pos];
     cnt[idx] = t[idx];
     return;
   }
   int mid = (lf + rg) >> 1;
   if (pos <= mid)
     upd(pos, 2 * idx + 1, lf, mid);
   else
     upd(pos, 2 * idx + 2, mid + 1, rg);
   cnt[idx] = cnt[2 * idx + 1] + cnt[2 * idx + 2];
   for (int i = 0; i < int(5); ++i) {
     long long& ans = sum[idx][i];
     int f = (cnt[2 * idx + 1])  5;
     f = (i - f + 5)  5;
     ans = sum[2 * idx + 1][i] + sum[2 * idx + 2][f];
   }
 }
 void change(int val) {
   int pos = lower_bound(a, a + sza, val) - a;
   upd(pos, 0, 0, sza - 1);
 }
 inline long long getSum() { return sum[0][2]; }
 int main() {
   int n;
   scanf( d , &n);
   gets(buf);
   vector<pair<int, int> > q;
   for (int i = 0; i < int(n); ++i) {
     gets(buf);
     if (buf[0] == 'a') {
       int val;
       sscanf(buf,  add d , &val);
       q.push_back(make_pair(1, val));
       a[sza++] = val;
     }
     if (buf[0] == 'd') {
       int val;
       sscanf(buf,  del d , &val);
       q.push_back(make_pair(-1, val));
       a[sza++] = val;
     }
     if (buf[0] == 's') {
       q.push_back(make_pair(-1, -1));
     }
   }
   sort(a, a + sza);
   sza = unique(a, a + sza) - a;
   for (int i = 0; i < int(n); ++i) {
     if (q[i] == pair<int, int>(-1, -1)) {
       printf( extra
 , getSum());
       continue;
     }
     if (q[i].first == 1) {
       change(q[i].second);
     } else {
       change(q[i].second);
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int a[100001];
 int getBound(int start, int dir, int size, int k) {
   int cnt = 0;
   bool seen[100001];
   fill(seen, seen + 100001, false);
   for (int i = start; i <= size && i > 0; i += dir) {
     if (!seen[a[i]]) cnt++, seen[a[i]] = true;
     if (cnt == k) return i;
   }
   return -1;
 }
 int main() {
   int n, k;
   cin >> n >> k;
   for (int i = 1; i <= n; i++) cin >> a[i];
   int right = getBound(1, 1, n, k);
   if (right == -1)
     cout << -1 <<     << -1 << endl;
   else {
     int left = getBound(right, -1, n, k);
     cout << left <<     << right << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long MAX = 10e5;
 vector<long long> graph[MAX];
 queue<long long> q;
 bool visit[MAX];
 long long a[MAX];
 long long s[MAX];
 long long parent[MAX];
 int main() {
   memset(visit, false, sizeof(visit));
   long long nodes;
   cin >> nodes;
   for (auto i = 2; i <= nodes; ++i) {
     long long tmp;
     cin >> tmp;
     parent[i] = tmp;
     graph[i].push_back(tmp);
     graph[tmp].push_back(i);
   }
   for (auto i = 1; i <= nodes; ++i) {
     cin >> s[i];
   }
   a[1] = s[1];
   q.push(1);
   visit[1] = true;
   while (!q.empty()) {
     long long n = q.front();
     q.pop();
     if (n != 1) {
       if (s[n] == -1) {
         s[n] = s[parent[n]];
         if (graph[n].size() > 1) {
           long long mini = 10e9;
           for (auto v : graph[n]) {
             if (v == parent[n]) continue;
             mini = min(mini, s[v]);
           }
           if (mini < s[n]) {
             cout << -1;
             return 0;
           } else {
             a[n] = mini - s[n];
             s[n] = mini;
           }
         } else {
           a[n] = 0;
           s[n] = s[parent[n]];
         }
       } else {
         a[n] = s[n] - s[parent[n]];
       }
     }
     for (auto p : graph[n]) {
       if (visit[p]) continue;
       q.push(p);
       visit[p] = true;
     }
   }
   long long ans = 0;
   for (auto i = 1; i <= nodes; i++) {
     ans += a[i];
   }
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void solve() {
   string s;
   cin >> s;
   string ans =   ;
   int cnt(0);
   for (int i = 0; i < s.size(); i++) {
     if (s[i] == '0' && cnt == 0) {
       cnt++;
     } else
       ans += s[i];
   }
   if (cnt == 0) {
     for (int i = 0; i < ans.size() - 1; i++) cout << ans[i];
   } else
     cout << ans;
 }
 int main() {
   long long t;
   t = 1;
   while (t--) solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
 const int N = 500005;
 vector<int> arr[N], cnt[N], adj[N];
 int vis[N], st[N], fin[N], dep[N];
 int tim;
 char inp[N];
 void dfs(int i, int d) {
   vis[i] = 1;
   dep[i] = d;
   st[i] = ++tim;
   arr[d].push_back(st[i]);
   int no = 0;
   for (int first = 0; first < (int)26; first++)
     no |= (first == inp[i] - 'a') << first;
   cnt[d].push_back(no);
   for (int v : adj[i])
     if (!vis[v]) dfs(v, d + 1);
   fin[i] = ++tim;
 }
 signed main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   int n, m;
   cin >> n >> m;
   for (int i = 0; i < (int)n - 1; i++) {
     int first;
     cin >> first;
     adj[first].push_back(i + 2);
     adj[i + 2].push_back(first);
   }
   for (int i = 0; i < (int)n; i++) cin >> inp[i + 1];
   dfs(1, 0);
   for (int i = 0; i < (int)N; i++) {
     for (int j = 1; j < cnt[i].size(); j++) {
       cnt[i][j] ^= cnt[i][j - 1];
     }
   }
   for (int wrd = 0; wrd < (int)m; wrd++) {
     int a, b;
     cin >> a >> b;
     b--;
     int no_odds = 0;
     vector<int>& v = arr[b];
     int l = lower_bound((v).begin(), (v).end(), st[a]) - v.begin();
     int r = upper_bound((v).begin(), (v).end(), fin[a]) - v.begin() - 1;
     if (l > r) {
       cout <<  Yes
 ;
       continue;
     }
     for (int first = 0; first < (int)26; first++) {
       int add = (cnt[b][r] >> first) & 1;
       int sub = (l == 0) ? 0 : ((cnt[b][l - 1] >> first) & 1);
       no_odds += (add - sub + 2)  2;
     }
     if (no_odds <= 1)
       cout <<  Yes
 ;
     else
       cout <<  No
 ;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long int t;
   cin >> t;
   while (t--) {
     long long int a[3], i;
     for (i = 0; i < 3; i++) cin >> a[i];
     sort(a, a + 3);
     if (a[2] <= a[1] + a[0] + 1)
       cout <<  YES  << endl;
     else
       cout <<  NO  << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 string to_string(string s) { return ' ' + s + ' '; }
 string to_string(const char* s) { return to_string((string)s); }
 string to_string(bool b) { return (b ?  true  :  false ); }
 template <typename A, typename B>
 string to_string(pair<A, B> p) {
   return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;
 }
 template <typename A>
 string to_string(A v) {
   bool first = true;
   string res =  { ;
   for (const auto& x : v) {
     if (!first) {
       res +=  ,  ;
     }
     first = false;
     res += to_string(x);
   }
   res +=  } ;
   return res;
 }
 void debug_out() { cerr << endl; }
 template <typename Head, typename... Tail>
 void debug_out(Head H, Tail... T) {
   cerr <<     << to_string(H);
   debug_out(T...);
 }
 template <int MOD_>
 struct modnum {
   static constexpr int MOD = MOD_;
   static_assert(MOD_ > 0,  MOD must be positive );

  private:
   using ll = long long;
   int v;
   static int minv(int a, int m) {
     a = m;
     assert(a);
     return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
   }

  public:
   modnum() : v(0) {}
   modnum(ll v_) : v(int(v_  MOD)) {
     if (v < 0) v += MOD;
   }
   explicit operator int() const { return v; }
   friend std::ostream& operator<<(std::ostream& out, const modnum& n) {
     return out << int(n);
   }
   friend std::istream& operator>>(std::istream& in, modnum& n) {
     ll v_;
     in >> v_;
     n = modnum(v_);
     return in;
   }
   friend bool operator==(const modnum& a, const modnum& b) {
     return a.v == b.v;
   }
   friend bool operator!=(const modnum& a, const modnum& b) {
     return a.v != b.v;
   }
   modnum inv() const {
     modnum res;
     res.v = minv(v, MOD);
     return res;
   }
   friend modnum inv(const modnum& m) { return m.inv(); }
   modnum neg() const {
     modnum res;
     res.v = v ? MOD - v : 0;
     return res;
   }
   friend modnum neg(const modnum& m) { return m.neg(); }
   modnum operator-() const { return neg(); }
   modnum operator+() const { return modnum(*this); }
   modnum& operator++() {
     v++;
     if (v == MOD) v = 0;
     return *this;
   }
   modnum& operator--() {
     if (v == 0) v = MOD;
     v--;
     return *this;
   }
   modnum& operator+=(const modnum& o) {
     v -= MOD - o.v;
     v = (v < 0) ? v + MOD : v;
     return *this;
   }
   modnum& operator-=(const modnum& o) {
     v -= o.v;
     v = (v < 0) ? v + MOD : v;
     return *this;
   }
   modnum& operator*=(const modnum& o) {
     v = int(ll(v) * ll(o.v)  MOD);
     return *this;
   }
   modnum& operator/=(const modnum& o) { return *this *= o.inv(); }
   friend modnum operator++(modnum& a, int) {
     modnum r = a;
     ++a;
     return r;
   }
   friend modnum operator--(modnum& a, int) {
     modnum r = a;
     --a;
     return r;
   }
   friend modnum operator+(const modnum& a, const modnum& b) {
     return modnum(a) += b;
   }
   friend modnum operator-(const modnum& a, const modnum& b) {
     return modnum(a) -= b;
   }
   friend modnum operator*(const modnum& a, const modnum& b) {
     return modnum(a) *= b;
   }
   friend modnum operator/(const modnum& a, const modnum& b) {
     return modnum(a) /= b;
   }
 };
 using num = modnum<1000000007>;
 const int mod = 1e9 + 7;
 num power(num a, int64_t b) {
   if (b == 0) return 1;
   num res = power(a, b / 2);
   if (b & 1) return res * res * a;
   return res * res;
 }
 bool checkinter(pair<int, int> x, pair<int, int> y) {
   if (x.first > y.first) swap(x, y);
   return x.first <= y.first && y.first <= x.second;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   if (fopen( input.txt ,  r )) {
     freopen( input.txt ,  r , stdin);
     freopen( output.txt ,  w , stdout);
   }
   int64_t N, M, K, R, C, Ax, Bx, Ay, By;
   cin >> N >> M >> K >> R >> C >> Ax >> Ay >> Bx >> By;
   if (!checkinter(make_pair(Ax, Ax + R - 1), make_pair(Bx, Bx + R - 1)) or
       !checkinter(make_pair(By, By + C - 1), make_pair(Ay, Ay + C - 1))) {
     num res = 0;
     res = power(K, 1ll * N * M - 2ll * R * C);
     res *= power(K, 1ll * R * C);
     cout << res;
     return 0;
   }
   if (Ax > Bx) swap(Ax, Bx), swap(Ay, By);
   if (By < Ay) {
     int diff = abs(By + C - 1 - Ay + 1);
     By = Ay + C - 1 - diff + 1;
   }
   int64_t sharearea = 1ll * ((Ay + C - 1) - By + 1) * ((Ax + R - 1) - Bx + 1);
   int64_t area = 2ll * R * C - sharearea;
   int64_t remainarea = 1ll * N * M - area;
   num res = power(K, remainarea);
   if (Ax == Bx and Ay == By)
     res *= power(K, R * C);
   else
     res *= power(K, 1ll * R * C - sharearea);
   cout << res;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct rangeincrease {
   int l, r;
 };
 rangeincrease actions[100001];
 rangeincrease inprogress[100001];
 int actionL = 0;
 int nums[100001];
 int opened = 0;
 int main() {
   int n;
   int i;
   cin >> n;
   for (i = 1; i <= n; i++) {
     cin >> nums[i];
   }
   for (i = 1; i <= n; i++) {
     while (nums[i] > opened) {
       opened++;
       inprogress[opened].l = i;
     }
     while (nums[i] < opened) {
       inprogress[opened].r = i - 1;
       actionL++;
       actions[actionL].l = inprogress[opened].l;
       actions[actionL].r = inprogress[opened].r;
       opened--;
     }
   }
   while (opened > 0) {
     inprogress[opened].r = n;
     actionL++;
     actions[actionL].l = inprogress[opened].l;
     actions[actionL].r = inprogress[opened].r;
     opened--;
   }
   cout << actionL << endl;
   for (i = 1; i <= actionL; i++) {
     cout << actions[i].l <<     << actions[i].r << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( Ofast )
 #pragma GCC target( avx,avx2,fma )
 using namespace std;
 bool ispoweroftwo(long long n) { return n & (!(n & (n - 1))); }
 long long mod = 1000000007;
 long long dx[] = {1, 0, -1, 0};
 long long dy[] = {0, -1, 0, 1};
 bool test = 0;
 const long long inf = 1e18;
 const long long N = 1e5 + 5;
 long long cache[N][4][4];
 long long k, n;
 long long color[N][3];
 vector<long long> adj[N];
 long long dp(long long u, long long f = 3, long long f1 = 3, long long p = -1) {
   long long &ans = cache[u][f][f1];
   if (ans != -1) return ans;
   long long kid1 = -1, kid2 = -1;
   for (auto it : adj[u]) {
     if (it == p) continue;
     if (kid1 == -1)
       kid1 = it;
     else
       kid2 = it;
   }
   if (kid1 == -1) return ans = 0;
   if (kid2 != -1) {
     vector<long long> c1, c2, c3;
     for (long long i = 0; i < 3; ++i) {
       if (i == f) continue;
       c1.emplace_back(color[kid1][i] + dp(kid1, i, f, u));
       c3.emplace_back(i);
     }
     for (long long i = 0; i < 3; ++i) {
       if (i == f) continue;
       c2.emplace_back(color[kid2][i] + dp(kid2, i, f, u));
     }
     ans = min(c1[0] + c2[1], c1[1] + c2[0]);
     return ans;
   }
   ans = inf;
   for (long long i = 0; i < 3; ++i) {
     if (i == f or i == f1) continue;
     ans = min(ans, color[kid1][i] + dp(kid1, i, f, u));
   }
   return ans;
 }
 vector<long long> col(N);
 void path(long long u, long long f, long long f1 = 3, long long p = -1) {
   long long &ans = cache[u][f][f1];
   long long kid1 = -1, kid2 = -1;
   for (auto it : adj[u]) {
     if (it == p) continue;
     if (kid1 == -1)
       kid1 = it;
     else
       kid2 = it;
   }
   if (kid1 == -1) return;
   if (kid2 != -1) {
     vector<long long> c1, c2, c3;
     for (long long i = 0; i < 3; ++i) {
       if (i == f) continue;
       c1.emplace_back(color[kid1][i] + cache[kid1][i][f]);
       c3.emplace_back(i);
     }
     for (long long i = 0; i < 3; ++i) {
       if (i == f) continue;
       c2.emplace_back(color[kid2][i] + cache[kid2][i][f]);
     }
     if (ans != c1[0] + c2[1]) swap(kid1, kid2);
     col[kid1] = c3[0] + 1;
     col[kid2] = c3[1] + 1;
     path(kid1, c3[0], f, u);
     path(kid2, c3[1], f, u);
     return;
   }
   for (long long i = 0; i < 3; ++i) {
     if (i == f or i == f1) continue;
     if (ans == color[kid1][i] + cache[kid1][i][f]) {
       col[kid1] = i + 1;
       path(kid1, i, f, u);
     }
   }
 }
 void solve(long long tc = 0) {
   memset(cache, -1, sizeof(cache));
   cin >> n;
   for (long long i = 0; i < 3; ++i)
     for (long long j = 1; j <= n; ++j) cin >> color[j][i];
   for (long long i = 1, x, y; i < n; ++i) {
     cin >> x >> y;
     adj[x].emplace_back(y);
     adj[y].emplace_back(x);
   }
   for (long long i = 1; i <= n; ++i) {
     if (adj[i].size() >= 3) {
       cout <<  -1
 ;
       return;
     }
   }
   adj[0].emplace_back(1);
   long long ans = dp(0, 3);
   cout << ans <<
 ;
   path(0, 3);
   for (long long i = 1; i <= n; ++i) cout << col[i] <<    ;
   cout <<
 ;
 }
 signed main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   long long t = 1;
   if (test) cin >> t;
   for (long long i = 1; i <= t; ++i) {
     solve(i);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long MX = 200005;
 long long n, m;
 vector<long long> adj[2][MX];
 long long st[MX], fin[MX];
 long long deg[2][MX];
 long long ans, tim;
 long long cur = 1;
 pair<long long, long long> seg[4 * MX];
 long long lazy[4 * MX];
 pair<long long, long long> merge(pair<long long, long long> x,
                                  pair<long long, long long> y) {
   if (x.first == y.first) return {x.first, x.second + y.second};
   return min(x, y);
 }
 void build(long long node, long long l, long long r) {
   if (l == r) {
     seg[node] = {0, 1};
     return;
   }
   long long mid = (l + r) / 2;
   build(2 * node, l, mid);
   build(2 * node + 1, mid + 1, r);
   seg[node] = merge(seg[2 * node], seg[2 * node + 1]);
 }
 void propagate(long long node, long long l, long long r) {
   seg[node].first += lazy[node];
   if (l != r) {
     lazy[2 * node] += lazy[node];
     lazy[2 * node + 1] += lazy[node];
   }
   lazy[node] = 0;
 }
 void update(long long node, long long l, long long r, long long x, long long y,
             long long val) {
   propagate(node, l, r);
   if (l > y or r < x) return;
   if (l >= x and r <= y) {
     lazy[node] += val;
     propagate(node, l, r);
     return;
   }
   long long mid = (l + r) / 2;
   update(2 * node, l, mid, x, y, val);
   update(2 * node + 1, mid + 1, r, x, y, val);
   seg[node] = merge(seg[2 * node], seg[2 * node + 1]);
 }
 void dfs(long long u) {
   st[u] = tim++;
   for (auto v : adj[1][u]) {
     dfs(v);
   }
   fin[u] = tim;
 }
 void solve(long long u) {
   update(1, 0, cur - 1, st[u], fin[u] - 1, 1);
   if (!seg[1].first) ans -= seg[1].second;
   for (auto v : adj[0][u]) {
     solve(v);
   }
   update(1, 0, cur - 1, st[u], fin[u] - 1, -1);
 }
 signed main() {
   cin >> n >> m;
   vector<vector<long long> > index(n, vector<long long>(m, -1));
   vector<vector<char> > a(n, vector<char>(m));
   for (long long i = 0; i < n; i++) {
     for (long long j = 0; j < m; j++) {
       cin >> a[i][j];
       if (a[i][j] == 'L') {
         index[i][j] = cur;
         index[i][j + 1] = cur;
         cur++;
       } else if (a[i][j] == 'U') {
         index[i][j] = cur;
         index[i + 1][j] = cur;
         cur++;
       }
     }
   }
   cur--;
   for (long long i = 0; i < n; i++) {
     for (long long j = 0; j < m; j++) {
       if (a[i][j] == 'L' and j + 2 < m) {
         adj[(i + j)  2][index[i][j + 2]].push_back(index[i][j]);
         deg[(i + j)  2][index[i][j]]++;
       }
       if (a[i][j] == 'R' and j - 2 >= 0) {
         adj[(i + j)  2][index[i][j - 2]].push_back(index[i][j]);
         deg[(i + j)  2][index[i][j]]++;
       }
       if (a[i][j] == 'U' and i + 2 < n) {
         adj[(i + j)  2][index[i + 2][j]].push_back(index[i][j]);
         deg[(i + j)  2][index[i][j]]++;
       }
       if (a[i][j] == 'D' and i - 2 >= 0) {
         adj[(i + j)  2][index[i - 2][j]].push_back(index[i][j]);
         deg[(i + j)  2][index[i][j]]++;
       }
     }
   }
   ans = (n * m * n * m) / 4;
   tim = 0;
   for (long long i = 1; i < cur + 1; i++) {
     if (!deg[1][i]) dfs(i);
   }
   build(1, 0, cur - 1);
   for (long long i = 1; i < cur + 1; i++) {
     if (!deg[0][i]) solve(i);
   }
   cout << ans <<
 ;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 205, inf = 1e9;
 int n, a[N];
 int tot, lnk[N], fro[N * N * 2], nxt[N * N * 2], son[N * N * 2], c[N * N * 2],
     ori[N * N * 2];
 int S, T, dep[N], cur[N];
 queue<int> q;
 int cnt;
 bool vis[N];
 vector<int> ans[N];
 bool isprm(int x) {
   if (x == 2 || x == 3 || x == 5 || x == 7) return 1;
   for (int i = 2; i <= sqrt(x); ++i)
     if (x  i == 0) return 0;
   return 1;
 }
 void add(int x, int y, int z) {
   nxt[++tot] = lnk[x], lnk[x] = tot;
   fro[tot] = x, son[tot] = y, c[tot] = ori[tot] = z;
 }
 struct Dinic {
   bool bfs(int x = 0) {
     memset(dep, 0, sizeof dep), dep[S] = 1;
     for (; !q.empty(); q.pop())
       ;
     q.push(S);
     for (; !q.empty();) {
       x = q.front(), q.pop();
       for (int j = lnk[x]; j; j = nxt[j]) {
         if (!dep[son[j]] && c[j]) {
           dep[son[j]] = dep[x] + 1;
           q.push(son[j]);
         }
       }
     }
     return dep[T];
   }
   int dfs(int x, int f, int ret = 0) {
     if (x == T) return f;
     for (int &j = cur[x]; j; j = nxt[j]) {
       if (dep[son[j]] == dep[x] + 1 && c[j]) {
         int delta = dfs(son[j], min(f, c[j]));
         c[j] -= delta, c[j ^ 1] += delta;
         ret += delta, f -= delta;
       }
     }
     return ret;
   }
   int answer(int ret = 0) {
     for (; bfs();) {
       for (int i = S; i <= T; ++i) cur[i] = lnk[i];
       ret += dfs(S, inf);
     }
     return ret;
   }
 } network;
 void dfs(int x, int s) {
   vis[x] = 1, ans[cnt].push_back(x);
   if (a[x] & 1) {
     for (int j = lnk[x]; j; j = nxt[j]) {
       if (c[j] != 0 || son[j] == S || son[j] == T) continue;
       if (!vis[son[j]]) {
         dfs(son[j], s);
         break;
       }
     }
   } else {
     for (int j = lnk[x]; j; j = nxt[j]) {
       if (c[j ^ 1] != 0 || son[j] == S || son[j] == T) continue;
       if (!vis[son[j]]) {
         dfs(son[j], s);
         break;
       }
     }
   }
 }
 int main() {
   cin >> n, tot = 1, S = 0, T = n + 1;
   for (int i = 1; i <= n; ++i) {
     scanf( d , &a[i]);
     if (a[i] & 1)
       add(S, i, 2), add(i, S, 0);
     else
       add(i, T, 2), add(T, i, 0);
   }
   for (int i = 1; i <= n; ++i) {
     for (int j = 1; j <= n; ++j)
       if (isprm(a[i] + a[j]) && a[i]  2 == 1 && a[j]  2 == 0)
         add(i, j, 1), add(j, i, 0);
   }
   int fl = network.answer();
   if (fl != n) return puts( Impossible ), 0;
   for (int i = 1; i <= n; ++i)
     if (a[i] & 1) {
       if (!vis[i]) ++cnt, dfs(i, i);
     }
   printf( d
 , cnt);
   for (int i = 1; i <= cnt; ++i) {
     printf( d , ans[i].size());
     for (int j = 0; j < ans[i].size(); ++j) printf(  d , ans[i][j]);
     puts(  );
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int NMax = 1003;
 enum directions { EAST, NORTH };
 struct point {
   int x, y;
 };
 point a[NMax];
 int n;
 int test(int searchDir, point a[], long double x, long double y) {
   if (searchDir == NORTH) {
     int nr = 0;
     for (int i = 1; i <= n; ++i) {
       if (a[i].y >= y &&
           (((long double)a[i].x >= x && x <= (long double)a[i + 1].x) ||
            ((long double)a[i].x <= x && x >= (long double)a[i + 1].x))) {
         nr++;
       }
     }
     return (nr & 1);
   } else {
     int nr = 0;
     for (int i = 1; i <= n; ++i) {
       if (a[i].x >= x &&
           (((long double)a[i].y >= y && y <= (long double)a[i + 1].y) ||
            ((long double)a[i].y <= y && y >= (long double)a[i + 1].y))) {
         nr++;
       }
     }
     return (nr & 1);
   }
 }
 int main() {
   cin >> n;
   for (int i = 1; i <= n + 1; ++i) {
     cin >> a[i].x >> a[i].y;
   }
   int ans = 0;
   for (int i = 2; i <= n + 1; ++i) {
     if (a[i].x == a[i - 1].x) {
       if (a[i].y > a[i - 1].y) {
         ans += test(EAST, a, a[i].x, a[i].y + 0.5);
       } else {
         ans += test(EAST, a, a[i].x, a[i].y - 0.5);
       }
     } else {
       if (a[i].x > a[i - 1].x) {
         ans += test(NORTH, a, a[i].x + 0.5, a[i].y);
       } else {
         ans += test(NORTH, a, a[i].x - 0.5, a[i].y);
       }
     }
   }
   cout << ans << '
';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int mod = 1051131;
 const int Inv2 = (mod + 1) >> 1;
 inline void setIO(string a) {}
 long long Power;
 int m, s, n, nn;
 int a[(1 << 25) + 23];
 void work(int n, int p, int q) {
   if (n == 1) {
     int &An = a[1];
     (p += q) = mod;
     for (long long c = Power; c; c >>= 1, p = 1ll * p * p  mod)
       if (c & 1) An = 1ll * An * p  mod;
     return;
   }
   int t = n >> 1, tt = 1ll * t * p  mod;
   int ttp = (p + q + mod - tt)  mod, tttp = 1;
   for (long long c = Power; c; c >>= 1, ttp = 1ll * ttp * ttp  mod)
     if (c & 1) tttp = 1ll * tttp * ttp  mod;
   int xi = (1ll * t * p  mod - p + q + mod)  mod;
   for (int i = (1); i <= (t); i++) {
     int A = a[i], B = a[i + t];
     a[i] = (A + B)  mod;
     a[i + t] = (A + mod - B)  mod;
     a[i + t] = 1ll * a[i + t] * tttp  mod;
   }
   work(n >> 1, (p + p)  mod, xi);
   for (int i = (1); i <= (t); i++) {
     int A = a[i], B = a[i + t];
     a[i] = (A + B)  mod;
     a[i + t] = (A + mod - B)  mod;
     a[i] = 1ll * a[i] * Inv2  mod;
     a[i + t] = 1ll * a[i + t] * Inv2  mod;
   }
 }
 int main() {
   scanf( d , &m);
   cin >> Power;
   scanf( d , &s);
   for (int i = (1); i <= (s); i++) scanf( d , &a[i]);
   n = 1 << m;
   nn = n;
   for (int i = (s + 1); i <= (n); i++)
     a[i] = (101ll * a[i - s] + 10007)  1051131;
   work(n, 1, 0);
   int ans = 0;
   for (int i = (1); i <= (n); i++) ans ^= a[i];
   printf( d
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, arr[30010], book[30010];
 bool judge() {
   int ps, gap;
   int t1 = 1, t2;
   while (t1 <= n && book[t1]) t1++;
   t2 = t1 + 1;
   if (t1 > n) return false;
   while (t2 <= n && book[t2]) t2++;
   if (t2 > n) return true;
   gap = arr[t2] - arr[t1];
   ps = t2;
   for (int i = t2 + 1; i <= n; i++)
     if (!book[i]) {
       if (arr[i] - arr[ps] == gap)
         ps = i;
       else
         return false;
     }
   return true;
 }
 int main() {
   scanf( d , &n);
   for (int i = 1; i <= n; i++) scanf( d , &arr[i]);
   if (n == 2)
     printf( d
d , arr[1], arr[2]);
   else {
     int x[3] = {arr[2] - arr[1], arr[3] - arr[2], arr[3] - arr[1]};
     int flag = 0;
     for (int i = 0; i < 3; i++) {
       int st = 4, tmp = arr[3];
       memset(book, 0, sizeof(book));
       if (i == 0) {
         book[2] = book[1] = 1;
         st = 3;
         tmp = arr[2];
       } else if (i == 1)
         book[2] = book[3] = 1;
       else
         book[1] = book[3] = 1;
       for (int ii = st; ii <= n; ii++)
         if (arr[ii] == tmp + x[i]) {
           book[ii] = 1;
           tmp = arr[ii];
         }
       if (judge()) {
         flag = 1;
         break;
       } else {
         int p = n;
         while (!book[p]) p--;
         book[p] = 0;
         if (judge()) {
           flag = 1;
           break;
         }
       }
     }
     if (flag) {
       for (int i = 1; i <= n; i++)
         if (book[i]) printf( d  , arr[i]);
       printf(
 );
       for (int i = 1; i <= n; i++)
         if (!book[i]) printf( d  , arr[i]);
     } else
       printf( No solution );
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int ekub(int a, int b) { return b == 0 ? a : ekub(b, a  b); }
 long long s[51][51];
 int main() {
   long long i, j, n, m, a, b, ans = 1e9;
   cin >> n >> m;
   for (i = 1; i <= n; i++)
     for (j = 1; j <= m; j++) {
       cin >> s[i][j];
       s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
     }
   cin >> a >> b;
   for (i = a; i <= n; i++)
     for (j = b; j <= m; j++)
       ans = min(ans, s[i][j] - s[i - a][j] - s[i][j - b] + s[i - a][j - b]);
   for (i = b; i <= n; i++)
     for (j = a; j <= m; j++)
       ans = min(ans, s[i][j] - s[i - b][j] - s[i][j - a] + s[i - b][j - a]);
   cout << ans;
 }


#include <bits/stdc++.h>
 namespace P_TEMPLATE {
 class fastin {
  private:
   int _ch, _f;

  public:
   inline fastin& operator>>(char& c) {
     c = getchar();
     return *this;
   }
   template <typename _Tp>
   inline fastin& operator>>(_Tp& _x) {
     _x = 0;
     while (!isdigit(_ch)) _f |= (_ch == 45), _ch = getchar();
     while (isdigit(_ch))
       _x = (_x << 1) + (_x << 3) + (_ch ^ 48), _ch = getchar();
     _f && (_x = -_x, _f = 0);
     return *this;
   }
   fastin() { _ch = _f = 0; }
 } fin;
 class fastout {
  private:
   int _num[32], _head;

  public:
   inline fastout& operator<<(char c) {
     putchar(c);
     return *this;
   }
   template <typename _Tp>
   inline fastout& operator<<(_Tp _x) {
     _Tp _k;
     if (_x == 0) {
       putchar('0');
       return *this;
     }
     if (_x < 0) putchar('-'), _x = -_x;
     while (_x > 0)
       _k = _x / 10, ++_head, _num[_head] = (_x - (_k << 1) - (_k << 3)) ^ 48,
       _x = _k;
     while (_head > 0) putchar(_num[_head]), --_head;
     return *this;
   }
   fastout() { _head = 0; }
 } fout;
 inline void P_INIT() {}
 }  // namespace P_TEMPLATE
 using namespace P_TEMPLATE;
 using namespace std;
 const int maxn = 1000004, maxm = 104;
 const int mod = 1000000007, inf = 1201201201;
 int n, k, p;
 char s[maxn][maxm];
 int len[maxn];
 int book[28], cnt[28];
 vector<int> e[28];
 queue<int> q;
 int topo[28], indx;
 inline bool check() {
   for (register int i = 1; i <= 26; ++i)
     if (!cnt[i]) q.push(i), topo[++indx] = i;
   while (!q.empty()) {
     int t = q.front();
     q.pop();
     for (register int i = 0; i < e[t].size(); ++i) {
       --cnt[e[t][i]];
       if (cnt[e[t][i]] == 0) q.push(e[t][i]), topo[++indx] = e[t][i];
     }
   }
   return indx == 26;
 }
 signed main() {
   P_INIT();
   fin >> n >> k;
   for (register int i = 1; i <= n; ++i) {
     fin >> p;
     for (register int j = 1; j <= k; ++j) {
       scanf( s , s[p * k + j] + 1), len[p * k + j] = strlen(s[p * k + j] + 1);
       for (register int t = 1; t <= len[p * k + j]; ++t)
         book[s[p * k + j][t] - 'a' + 1] = 1;
     }
   }
   for (register int i = 1; i < n * k; ++i) {
     bool flag = 0;
     for (register int j = 1; j <= std::min(len[i], len[i + 1]); ++j)
       if (s[i][j] != s[i + 1][j]) {
         e[s[i][j] - 'a' + 1].push_back(s[i + 1][j] - 'a' + 1);
         ++cnt[s[i + 1][j] - 'a' + 1];
         flag = 1;
         break;
       }
     if (!flag && len[i] > len[i + 1]) {
       puts( IMPOSSIBLE );
       return 0;
     }
   }
   if (check()) {
     for (register int i = 1; i <= 26; ++i)
       if (book[topo[i]]) fout << char(topo[i] - 1 + 'a');
   } else
     puts( IMPOSSIBLE );
   return 0;
 }


#include <bits/stdc++.h>
 #pragma comment(linker,  /STACK:66777216 )
 using namespace std;
 const int N = 100007;
 int n, a[N], cnt[N];
 vector<int> D[N];
 long long power(long long a, long long b) {
   if (b == 0) {
     return 1;
   }
   if (b & 1) {
     return (a * power(a, b - 1))  1000000007LL;
   }
   long long ret = power(a, b >> 1);
   return (ret * ret)  1000000007LL;
 }
 int main() {
   scanf( d , &n);
   for (int i = 0; i < n; ++i) {
     scanf( d , &a[i]);
   }
   sort(a, a + n);
   for (int i = 1; i <= a[n - 1]; ++i) {
     for (int j = i; j <= a[n - 1]; j += i) {
       D[j].push_back(i);
     }
   }
   long long ans = 0;
   for (int m = 1; m <= a[n - 1]; ++m) {
     vector<int> &d = D[m];
     int nd = (int)(d).size();
     for (int i = 0; i < nd; ++i) {
       cnt[i] = n - (lower_bound(a, a + n, d[i]) - a);
     }
     long long cur =
         (power(nd, cnt[nd - 1]) - power(nd - 1, cnt[nd - 1]) + 1000000007LL)
         1000000007LL;
     for (int i = 0; i < nd - 1; ++i) {
       cur = (cur * power(i + 1, cnt[i] - cnt[i + 1]))  1000000007LL;
     }
     ans = (ans + cur)  1000000007LL;
   }
   printf( d
 , (int)ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void init_code() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
 }
 int main() {
   init_code();
   int t;
   cin >> t;
   while (t--) {
     int n;
     cin >> n;
     vector<pair<int, int>> v;
     vector<pair<int, int>> v1;
     for (int i = 0; i < n; i++) {
       int x, y;
       cin >> x >> y;
       v1.push_back({x, y});
       v.push_back({x, y});
     }
     sort(v.begin(), v.end());
     int st = v[0].first;
     int ed = v[0].second;
     int cnt = 1;
     unordered_map<int, int> mp;
     mp[st] = 1;
     for (int i = 1; i < n; i++) {
       if (v[i].first <= ed) {
         mp[v[i].first] = cnt;
         ed = max(ed, v[i].second);
       } else {
         st = v[i].first;
         ed = v[i].second;
         if (cnt == 1) {
           cnt++;
         }
         mp[v[i].first] = cnt;
       }
     }
     if (cnt < 2) {
       cout <<  -1  << endl;
     } else {
       for (int i = 0; i < v1.size(); i++) {
         cout << mp[v1[i].first] <<    ;
       }
       cout << endl;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void solve() {}
 void no() {
   cout <<  NO  << '
';
   exit(0);
 }
 const long long maxn = 100050;
 long long a[maxn];
 long long psa[maxn];
 signed main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   long long n;
   cin >> n;
   for (long long i = 1; i <= n; i++) {
     cin >> a[i];
   }
   long long len = n;
   for (long long i = 1; i <= n; i++) {
     if (a[i] != a[1]) {
       len = i - 1;
       break;
     }
   }
   for (long long i = 1; i <= n; i++) {
     psa[i] = psa[i - 1] + a[i];
   }
   if (n  len) no();
   for (long long i = len; i <= n; i += len) {
     long long sum = psa[i] - psa[i - len];
     if (sum and sum != len) {
       no();
     }
     if (i >= len * 2) {
       if (sum == psa[i - len] - psa[i - 2 * len]) {
         no();
       }
     }
   }
   cout <<  YES  << '
';
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1234567;
 int pref[N], a[N], b[N];
 char c[N];
 int solve(vector<pair<int, int> > z, int b) {
   sort(z.begin(), z.end());
   int cnt = z.size();
   if (cnt < 2) {
     return 0;
   }
   pref[0] = 0;
   for (int i = 0; i < cnt; i++) {
     pref[i + 1] = max(pref[i], z[i].second);
   }
   int i = 0;
   int res = 0;
   for (int j = cnt - 1; j >= 0; j--) {
     while (i < j && z[i].first + z[j].first <= b) {
       i++;
     }
     i = min(i, j);
     if (i > 0) {
       res = max(res, pref[i] + z[j].second);
     }
   }
   return res;
 }
 int same(vector<pair<int, int> > &v, int b) {
   if (v.size() < 2) return 0;
   sort(v.begin(), v.end());
   vector<int> pre(v.size() + 1, 0);
   for (int i = 0; i < v.size(); i++) pre[i + 1] = max(pre[i], v[i].second);
   int i = 0, ans = 0;
   for (int j = v.size() - 1; j >= 0; j--) {
     while (i < j && v[i].first + v[j].first <= b) i++;
     i = min(i, j);
     if (i > 0) {
       ans = max(ans, v[j].second + pre[i]);
     }
   }
   return ans;
 }
 int main() {
   int n, C, D;
   scanf( d d d , &n, &C, &D);
   for (int i = 0; i < n; i++) {
     scanf( d d , a + i, b + i);
     c[i] = getchar();
     while (c[i] != 'C' && c[i] != 'D') {
       c[i] = getchar();
     }
   }
   int ans = 0;
   {
     int x = 0, y = 0;
     for (int i = 0; i < n; i++) {
       if (c[i] == 'C' && b[i] <= C) {
         x = max(x, a[i]);
       }
     }
     for (int i = 0; i < n; i++) {
       if (c[i] == 'D' && b[i] <= D) {
         y = max(y, a[i]);
       }
     }
     if (x > 0 && y > 0) {
       ans = max(ans, x + y);
     }
   }
   {
     vector<pair<int, int> > z;
     for (int i = 0; i < n; i++) {
       if (c[i] == 'C') {
         z.push_back(make_pair(b[i], a[i]));
       }
     }
     ans = max(ans, same(z, C));
   }
   {
     vector<pair<int, int> > z;
     for (int i = 0; i < n; i++) {
       if (c[i] == 'D') {
         z.push_back(make_pair(b[i], a[i]));
       }
     }
     ans = max(ans, same(z, D));
   }
   printf( d
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 inline int abs(int n) { return n < 0 ? -n : n; }
 bool board[20][20];
 int dx[] = {-3, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 3};
 int dy[] = {0, 1, -1, 2, -2, 3, -3, 2, -2, 1, -1, 0};
 int dfs(int p, int n, int m) {
   int mx = p, t, cnt = 0;
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < m; j++) {
       if (!board[i][j]) {
         board[i][j] = true;
         for (int k = 0; k < 12; k++) {
           int ic = i + dx[k], jc = j + dy[k];
           if (ic >= 0 && ic < n && jc >= 0 && jc < m && !board[ic][jc]) {
             board[ic][jc] = true;
             t = dfs(p + 2, n, m);
             mx < t && (mx = t);
             if (mx == ((m * n) | 1) - 1) return mx;
             board[ic][jc] = false;
           }
         }
         board[i][j] = false;
         cnt++;
         if (m * n - cnt <= mx) return mx;
       }
     }
   }
   return mx;
 }
 int ans[] = {0, 0, 0, 0, 2, 4};
 int main() {
   int m, n;
   scanf( dd , &m, &n);
   if (m < 10 && n < 10) {
     printf( d
 , dfs(0, n, m));
   } else if (m == 1) {
     printf( d
 , n / 6 * 6 + ans[n  6]);
   } else if (n == 1) {
     printf( d
 , m / 6 * 6 + ans[m  6]);
   } else {
     printf( lld
 , (((long long)(m)*n) | 1) - 1);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using db = long double;
 using pll = pair<long long, long long>;
 const long long sz = 300003;
 long long dp[sz][2], n;
 long long a[sz];
 long long dfs(long long i, long long par) {
   if (i >= n) return 0;
   long long &res = dp[i][par];
   if (res == -1) {
     res = 0;
     if (par) {
       res = a[i] + dfs(i + 1, par ^ 1);
     } else {
       res = -a[i] + dfs(i + 1, par ^ 1);
     }
     res = max({0LL, res, dfs(i + 1, par)});
   }
   return res;
 }
 int32_t main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   long long t, i, x, j, y, q, z, k;
   int kkr, csk;
   long long tt;
   cin >> tt;
   for (long long _tt = 0; _tt < tt; _tt++) {
     cin >> n >> q;
     for (int i = 0; i < n; i++) cin >> a[i];
     ;
     while (q-- > 0) {
       cin >> x >> y;
       x--, y--;
     }
     for (i = 0; i < n; i += 1) {
       memset(dp[i], -1, sizeof(dp[i]));
     }
     z = dfs(0, 1);
     42;
     cout << z << '
';
     ;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int t;
   cin >> t;
   while (t--) {
     int n;
     cin >> n;
     int arr[n];
     for (int i = 0; i < n; i++) cin >> arr[i];
     int counts[n + 1];
     memset(counts, 0, sizeof(counts));
     if (n == 1) {
       cout << 0 << endl;
       continue;
     }
     for (int i = 0; i < n; i++) counts[arr[i]]++;
     int dc = 0, rc = INT_MIN;
     for (int i = 0; i <= n; i++) {
       if (counts[i] > 0) dc++;
       rc = max(rc, counts[i]);
     }
     if (rc > 1) dc--;
     if (rc > dc + 1)
       cout << dc + 1 << endl;
     else
       cout << min(dc, rc) << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 105;
 const int inf = 10000000;
 int n, k;
 int l[N], r[N];
 int main() {
   scanf( dd , &n, &k);
   int midx = (k + 1) / 2, midy = (k + 1) / 2;
   for (int i = 0; i < n; i++) {
     int m, ans = inf, x, y1, y2;
     scanf( d , &m);
     for (int row = 1; row <= k; row++) {
       if (l[row] == 0 && r[row] == 0) {
         for (int a = 1; a + m - 1 <= k; a++) {
           int tot = 0, b = a + m - 1;
           for (int col = a; col <= b; col++) {
             tot += abs(row - midx) + abs(col - midy);
           }
           if (tot < ans) ans = tot, x = row, y1 = a, y2 = b;
         }
       } else {
         if (l[row] > m) {
           int tot = 0, a = l[row] - m, b = l[row] - 1;
           for (int col = a; col <= b; col++) {
             tot += abs(row - midx) + abs(col - midy);
           }
           if (tot < ans) ans = tot, x = row, y1 = a, y2 = b;
         }
         if (r[row] + m <= k) {
           int tot = 0, a = r[row] + 1, b = r[row] + m;
           for (int col = a; col <= b; col++)
             tot += abs(row - midx) + abs(col - midy);
           if (tot < ans) ans = tot, x = row, y1 = a, y2 = b;
         }
       }
     }
     if (ans == inf)
       puts( -1 );
     else {
       printf( d d d
 , x, y1, y2);
       if (r[x] == 0 && l[x] == 0)
         l[x] = y1, r[x] = y2;
       else
         l[x] = min(l[x], y1), r[x] = max(r[x], y2);
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 500010;
 const int M = 16;
 const int inf = 0x3f3f3f3f;
 const int S = 1 << 15;
 map<string, int> mp;
 int vs[15], n, m;
 char s[N][12], sx[12];
 int dp[S], cnt[S][16];
 int cal(int st) {
   int res = 0;
   while (st) {
     if (st & 1) res++;
     st >>= 1;
   }
   return res;
 }
 void prepare() {
   for (int i = 0; i < S; ++i) {
     int tmp = i;
     for (int j = 0; j < M; ++j) {
       tmp >>= 1;
       cnt[i][j] = cal(tmp);
     }
   }
 }
 int stx[N], pre[M];
 int main() {
   prepare();
   ios::sync_with_stdio(0);
   scanf( d , &n);
   for (int i = 0; i < n; ++i) {
     scanf( s , sx);
     mp[sx] = i;
   }
   int ans1 = -1, ans2 = 0, ans3 = 0;
   scanf( d , &m);
   for (int i = 0; i < m; ++i) {
     int k;
     scanf( d , &k);
     memset(vs, 0, sizeof vs);
     for (int j = 0; j < k; ++j) {
       scanf( s , s[j]);
       if (mp.find(s[j]) == mp.end()) continue;
       vs[mp[s[j]]] = 1;
     }
     int f = 0;
     for (int j = 0; j < n && !f; ++j)
       if (!vs[j]) f = 1;
     if (f) continue;
     int v = 0;
     memset(dp, 0x3f, sizeof dp);
     dp[0] = 0;
     int pre = 0;
     for (int j = 0; j < k; ++j) {
       if (mp.find(s[j]) == mp.end()) continue;
       int id = mp[s[j]], vst = 1 << id;
       if (pre & (1 << id)) continue;
       pre = (pre & ((1 << id) - 1) | (1 << id));
       for (int st = stx[j] & (vst - 1); st < (1 << n); ++st)
         if ((st & vst) == 0) {
           dp[st | vst] = min(dp[st | vst], dp[st] + cnt[st][id]);
         }
     }
     int tmp = n * (n - 1) / 2 - dp[(1 << n) - 1] + 1;
     if (ans1 == -1 || tmp > ans2 || (tmp == ans2 && dp[(1 << n) - 1] < ans3)) {
       ans1 = i;
       ans2 = tmp;
       ans3 = dp[(1 << n) - 1];
     }
   }
   if (ans1 == -1)
     puts( Brand new problem! );
   else {
     printf( d
 , ans1 + 1);
     printf( s ,  [: );
     for (int i = 0; i < ans2; ++i) putchar('|');
     puts( :] );
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename T>
 using V = vector<T>;
 const int MM = 5e5 + 5;
 using T = long long;
 bool QUERY;
 struct Line {
   mutable T a, b, p;
   T Eval(T first) const { return a * first + b; }
   bool operator<(const Line& o) const { return QUERY ? p < o.p : a < o.a; }
 };
 struct ConvexHull : multiset<Line> {
   const T kInf = numeric_limits<T>::max();
   T div(T a, T b) { return a / b - ((a ^ b) < 0 && a  b); }
   bool isect(iterator first, iterator second) {
     if (second == end()) {
       first->p = kInf;
       return false;
     }
     if (first->a == second->a) {
       first->p = first->b > second->b ? kInf : -kInf;
     } else {
       first->p = div(second->b - first->b, first->a - second->a);
     }
     return first->p >= second->p;
   }
   void InsertLine(T a, T b) {
     auto nx = insert({a, b, 0}), it = nx++, pv = it;
     while (isect(it, nx)) {
       nx = erase(nx);
     }
     if (pv != begin() && isect(--pv, it)) {
       isect(pv, it = erase(it));
     }
     while ((it = pv) != begin() && (--pv)->p >= it->p) {
       isect(pv, erase(it));
     }
   }
   T EvalMax(T first) {
     if (empty()) {
       return -2e18;
     }
     QUERY = 1;
     auto it = lower_bound({0, 0, first});
     QUERY = 0;
     return it->Eval(first);
   }
 };
 vector<vector<int>> tree;
 long long sub[MM];
 long long n;
 long long sq(long long e) { return e * e; }
 void dfs1(int cur, int par) {
   sub[cur] = 1;
   for (auto u : tree[cur]) {
     if (u != par) {
       dfs1(u, cur);
       sub[cur] += sub[u];
     }
   }
 }
 long long dp1[MM];
 void dfs2(int cur, int par) {
   dp1[cur] = sq(sub[cur]);
   for (int u : tree[cur]) {
     if (u != par) {
       dfs2(u, cur);
       dp1[cur] = min(dp1[cur], sq(sub[cur] - sub[u]) + dp1[u]);
     }
   }
 }
 vector<long long> ans;
 void dfs3(int cur, int par) {
   ConvexHull CH;
   ans[cur] = sq(n);
   for (int u : tree[cur]) {
     if (u != par) {
       dfs3(u, cur);
       long long val = dp1[u] - CH.EvalMax(sub[u]) + sq(sub[u]);
       ans[cur] = min(ans[cur], val);
       ans[cur] = min(ans[cur], dp1[u] + sq(n - sub[u]));
       CH.InsertLine(2 * (n - sub[u]), -(dp1[u] + sq(n - sub[u])));
     }
   }
   return;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   cin >> n;
   tree.resize(n);
   ans.resize(n);
   for (int i = 0; i < n - 1; i++) {
     int u, v;
     cin >> u >> v;
     u--;
     v--;
     tree[u].push_back(v);
     tree[v].push_back(u);
   }
   dfs1(0, -1);
   dfs2(0, -1);
   dfs3(0, -1);
   cout << (n * n - n) / 2 +
               (sq(n) - *min_element((ans).begin(), (ans).end())) / 2
        << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct Item {
   int x[3], y[3];
 };
 bool check(Item t);
 inline int Dist(int x1, int y1, int x2, int y2) {
   return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
 }
 int main() {
   Item it;
   for (int i = 0; i < 3; i++) cin >> it.x[i] >> it.y[i];
   if (check(it))
     cout <<  RIGHT
 ;
   else {
     bool f = false;
     for (int i = 0; i < 3; i++) {
       Item tmp = it;
       tmp.x[i]--;
       if (check(tmp)) {
         f = true;
         break;
       }
       tmp.x[i] += 2;
       if (check(tmp)) {
         f = true;
         break;
       }
     }
     for (int i = 0; i < 3; i++) {
       Item tmp = it;
       tmp.y[i]--;
       if (check(tmp)) {
         f = true;
         break;
       }
       tmp.y[i] += 2;
       if (check(tmp)) {
         f = true;
         break;
       }
     }
     if (f == true)
       cout <<  ALMOST
 ;
     else
       cout <<  NEITHER
 ;
   }
   return 0;
 }
 bool check(Item t) {
   int d[3];
   int xx[3], yy[3];
   d[0] = Dist(t.x[0], t.y[0], t.x[1], t.y[1]);
   d[1] = Dist(t.x[0], t.y[0], t.x[2], t.y[2]);
   d[2] = Dist(t.x[1], t.y[1], t.x[2], t.y[3]);
   if (!d[0] || !d[1] || !d[2]) return false;
   if (d[0] + d[1] == d[2] || d[1] + d[2] == d[0] || d[0] + d[2] == d[1])
     return false;
   xx[0] = t.x[0] - t.x[1];
   yy[0] = t.y[0] - t.y[1];
   xx[1] = t.x[0] - t.x[2];
   yy[1] = t.y[0] - t.y[2];
   xx[2] = t.x[1] - t.x[2];
   yy[2] = t.y[1] - t.y[2];
   if (xx[0] * xx[1] + yy[0] * yy[1] == 0 ||
       xx[0] * xx[2] + yy[0] * yy[2] == 0 || xx[1] * xx[2] + yy[1] * yy[2] == 0)
     return true;
   else
     return false;
 }


#include <bits/stdc++.h>
 using namespace std;
 void input(long long int n, long long int a[]) {
   for (long long int i = 0; i < n; ++i) cin >> a[i];
 }
 long long int bin_expo(long long int A, long long int B, long long int M) {
   long long int result = 1ll;
   while (B > 0) {
     if (B  2 == 1) {
       result = (result * A)  M;
     }
     A = (A * A)  M;
     B = B / 2;
   }
   return result;
 }
 long long int gcd(long long int a, long long int b) {
   if (b == 0) return a;
   return gcd(b, a  b);
 }
 long long int lcm(long long int a, long long int b) {
   return (a * b) / gcd(a, b);
 }
 long long int n, l;
 long long int a[101], b[101];
 long long int dp[4001][200][3];
 long long int solve(long long int left, long long int prev,
                     long long int flag) {
   if (left < 0) return 0LL;
   if (left == 0) return 1LL;
   if (dp[left][prev][flag] != -1) return dp[left][prev][flag];
   long long int res = 0;
   if (prev == -1) {
     for (long long int i = 0; i < n; ++i) {
       res += solve(left - a[i], i, 2);
       if (a[i] != b[i]) res += solve(left - b[i], i, 1);
       res = 1000000007;
     }
   } else {
     for (long long int i = 0; i < n; ++i) {
       if (i != prev) {
         long long int cur;
         if (flag == 1) cur = a[prev];
         if (flag == 2) cur = b[prev];
         if (a[i] == cur)
           res += solve(left - a[i], i, 2);
         else if (b[i] == cur)
           res += solve(left - b[i], i, 1);
         res = 1000000007;
       }
     }
   }
   return dp[left][prev][flag] = res  1000000007;
 }
 int main() {
   memset(dp, -1, sizeof(dp));
   cin >> n >> l;
   for (long long int i = 0; i < n; ++i) cin >> a[i] >> b[i];
   cout << solve(l, -1, 0) << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int sum, t, p, pos, a[100005], b[100005], n, f, c, f1;
   cin >> t;
   while (t--) {
     memset(a, 0, sizeof(a));
     memset(b, 0, sizeof(b));
     cin >> n;
     f = 1;
     sum = 0;
     p = 0;
     f1 = 1, c = 0;
     for (int i = 0; i < n; i++) cin >> a[i];
     for (int i = 0; i < n; i++) cin >> b[i];
     for (int i = 0; i < n; i++) {
       if (f == 1 && a[i] != b[i]) {
         if (p == 0) pos = i, p = 1, c = b[i] - a[i];
         sum++;
         f = 0;
       } else if (a[i] > b[i])
         f1 = 0;
       else if (a[i] == b[i])
         f = 1;
     }
     if (sum >= 2) {
       cout <<  NO  << endl;
     } else if (f1 == 0 || c < 0)
       cout <<  NO  << endl;
     else {
       if (sum == 0)
         cout <<  YES  << endl;
       else {
         for (int i = pos; a[i] != b[i]; i++) {
           if (b[i] - a[i] != c) f1 = 0;
         }
         if (f1 == 0)
           cout <<  NO  << endl;
         else
           cout <<  YES  << endl;
       }
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int left_[105], right_[105], mark[105];
 int main() {
   int n, j;
   std::ios::sync_with_stdio(0);
   while (~scanf( d , &n)) {
     int ans = 0;
     memset(left_, 0, sizeof(left_));
     memset(right_, 0, sizeof(right_));
     memset(mark, 0, sizeof(mark));
     for (int i = 1; i <= n; i++) {
       scanf( d d , &left_[i], &right_[i]);
       if (left_[i] == 0) mark[++ans] = i;
     }
     for (int i = 1; i < ans; i++) {
       for (j = mark[i]; right_[j] != 0; j = right_[j])
         ;
       left_[mark[i + 1]] = j;
       right_[j] = mark[i + 1];
     }
     for (int i = 1; i <= n; i++) printf( d d
 , left_[i], right_[i]);
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int gcd(int f, int s) {
   if (s == 0)
     return f;
   else
     return gcd(s, f  s);
 }
 int const N = 1000006;
 long long const M = 1020;
 long double const ep = .000000000000000001;
 long long arr[N], arr1[N];
 int main() {
   int n, m;
   scanf( d , &n);
   long long sum = 0, sum1 = 0;
   for (int i = 0; i < n; i++) {
     scanf( lld , arr + i);
     sum += arr[i];
   }
   scanf( d , &m);
   for (int i = 0; i < m; i++) {
     scanf( lld , arr1 + i);
     sum1 += arr1[i];
   }
   if (sum == sum1) {
     printf( 0
0 );
     return 0;
   }
   long long best = abs(sum - sum1);
   int ind = -1, ind1 = -1;
   for (int i = 0; i < n; i++) {
     long long temp = sum, temp1 = sum1;
     for (int x = 0; x < m; x++) {
       temp -= arr[i];
       temp += arr1[x];
       temp1 -= arr1[x];
       temp1 += arr[i];
       if (abs(temp - temp1) < best) {
         ind = i + 1, ind1 = x + 1;
         best = abs(temp - temp1);
       }
       temp = sum, temp1 = sum1;
     }
   }
   int indd = -1, indd1 = -1, indd2 = -1, indd21 = -1;
   vector<pair<long long, pair<int, int> > > v, v1;
   for (int i = 0; i < n; i++)
     for (int x = i + 1; x < n; x++)
       v.push_back(make_pair(arr[i] + arr[x], make_pair(i, x)));
   for (int i = 0; i < m; i++)
     for (int x = i + 1; x < m; x++)
       v1.push_back(make_pair(arr1[i] + arr1[x], make_pair(i, x)));
   sort(v1.begin(), v1.end());
   long long want = (sum - sum1) / 2;
   long long test = 1e17;
   long long num = -1;
   for (int i = 0; i < v.size(); i++) {
     int left = 0, right = v1.size() - 1, mid;
     while (left <= right) {
       mid = (left + right) / 2;
       long long curr = v[i].first - v1[mid].first;
       if (test > abs(curr - want)) {
         test = abs(curr - want);
         num = curr;
         indd = v[i].second.first + 1, indd1 = v[i].second.second + 1;
         indd2 = v1[mid].second.first + 1, indd21 = v1[mid].second.second + 1;
       }
       if (curr > want)
         left = mid + 1;
       else
         right = mid - 1;
     }
   }
   long long s = sum, s1 = sum1;
   s -= num;
   s1 += num;
   if (ind == -1 && indd == -1) {
     printf( lld
0 , best);
     return 0;
   }
   if (best > abs(s - s1)) {
     printf( lld
 , abs(s - s1));
     printf( 2
d d
d d , indd, indd2, indd1, indd21);
   } else {
     printf( lld
 , best);
     printf( 1
d d , ind, ind1);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long fact[100005];
 long long power(long long x, long long y, long long p) {
   long long res = 1;
   x = x  p;
   while (y > 0) {
     if (y & 1) res = ((res  p) * (x  p))  p;
     y = y >> 1;
     x = ((x  p) * (x  p))  p;
   }
   return res;
 }
 long long modInverse(long long n, long long p) { return power(n, p - 2, p); }
 long long nCrModFermat(long long n, long long r, long long p) {
   if (r == 0 || r == n) return 1;
   return (((fact[n]  p) * (modInverse(fact[r], p)  p))  p *
           (modInverse(fact[n - r], p)  p))
          p;
 }
 void sieve(vector<bool> &isPrime) {
   long long n = isPrime.size();
   isPrime[0] = false;
   isPrime[1] = false;
   for (long long i = 2; i * i <= n; i++) {
     if (isPrime[i] == true) {
       for (long long j = i * i; j <= n; j += i) isPrime[j] = false;
     }
   }
 }
 void addEdge(vector<long long> adj[], long long u, long long v) {
   adj[u].push_back(v);
   adj[v].push_back(u);
 }
 void BFS(long long s, vector<long long> adj[], vector<bool> &visited) {
   deque<long long> q;
   q.push_back(s);
   visited[s] = true;
   cout << s <<    ;
   while (!q.empty()) {
     long long p = q.front();
     q.pop_front();
     for (long long i = 0; i < adj[p].size(); i++) {
       if (visited[adj[p][i]] == false) {
         q.push_back(adj[p][i]);
         visited[adj[p][i]] = true;
         cout << adj[p][i] <<    ;
       }
     }
   }
 }
 void DFSUtil(long long u, vector<long long> adj[], vector<bool> &visited) {
   visited[u] = true;
   cout << u <<    ;
   for (long long i = 0; i < adj[u].size(); i++)
     if (visited[adj[u][i]] == false) DFSUtil(adj[u][i], adj, visited);
 }
 void DFS(vector<long long> adj[], long long V) {
   vector<bool> visited(V, false);
   for (long long u = 0; u < V; u++)
     if (visited[u] == false) DFSUtil(u, adj, visited);
 }
 void ChubbyCoder() {
   long long n;
   cin >> n;
   cout << n <<
 ;
 }
 signed main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   ;
   long long t;
   t = 1;
   cin >> t;
   while (t--) {
     ChubbyCoder();
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 bool seat[100][100] = {0};
 int main() {
   int n, k;
   scanf( d d , &n, &k);
   while (n--) {
     int num, x, l, r, min_sum;
     min_sum = 100000;
     scanf( d , &num);
     for (int i = 1; i <= k; i++) {
       for (int j = 1; j <= k - num + 1; j++) {
         int flag, sum;
         sum = 0;
         flag = 0;
         for (int m = j; m <= j + num - 1; m++) {
           if (seat[i][m]) {
             flag = 1;
             break;
           }
           sum += abs(i - k / 2 - 1) + abs(m - k / 2 - 1);
         }
         if (flag == 0 && sum < min_sum) {
           x = i;
           l = j;
           r = j + num - 1;
           min_sum = sum;
         }
       }
     }
     if (min_sum == 100000)
       printf( -1
 );
     else {
       printf( d d d
 , x, l, r);
       for (int i = l; i <= r; i++) seat[x][i] = 1;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   cin >> n;
   if (n  2 == 0) {
     if (n >= 8 && n  4 == 0)
       cout << ((n / 4) - 1) << endl;
     else if (n > 4 && n < 8)
       cout <<  1  << endl;
     else if (n <= 4)
       cout <<  0  << endl;
     else
       cout << (n / 4) << endl;
   } else {
     cout <<  0  << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, shet = 0;
   long long int ans = 0;
   cin >> n;
   ans = n;
   int* mas = new int[n];
   for (int i = 0; i < n; i++) {
     cin >> mas[i];
   }
   for (int i = 1; i < n; i++) {
     if (mas[i] == mas[i - 1]) {
       shet++;
       ans += shet;
     } else {
       shet = 0;
     }
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int gcd(int a, int b) {
   if (b == 0) return a;
   return gcd(b, a  b);
 }
 int main() {
   int a, i, temp;
   long long int sum = 0, n, fra;
   cin >> a;
   for (i = 2; i <= a - 1; i++) {
     temp = a;
     while (temp > 0) {
       sum += temp  i;
       temp = temp / i;
     }
   }
   temp = a - 2;
   fra = gcd(sum, temp);
   while (fra != 1) {
     sum = sum / fra;
     temp = temp / fra;
     fra = gcd(sum, temp);
   }
   cout << sum <<  /  << temp << endl;
 }