#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
struct node{
int x,y;
char dir;
}a[maxn];
int _,n,m,k,cnt;
int e[maxn],res[maxn],tot;
inline bool reserve_cmp(node s,node t){
if (s.x!=t.x){
return s.x>t.x;
}
return (s.dir=='U'||s.dir=='D')&&(t.dir=='L'||t.dir=='R');
}
inline bool cmp(node s,node t) {
if (s.x != t.x)
return s.x < t.x;
return (s.dir == 'U' || s.dir == 'D') && (t.dir == 'L' || t.dir == 'R');
}
inline int lowbit(int x) {
return x & -x;
}
inline void add(int pos,int val) {
while (pos <= tot + 100) {
res[pos] += val;
pos += lowbit(pos);
}
}
inline int query(int pos) {
int ans = 0;
while (pos) {
ans += res[pos];
pos -= lowbit(pos);
}
return ans;
}
int main() {
scanf("%d", &_);
while (_--) {
int ans = 1;
scanf("%d%d%d", &n, &m, &k);
cnt = 0;
for (int i = 1; i <= k; i++) {
scanf("%d %d %c", &a[i].x, &a[i].y, &a[i].dir);
e[++cnt] = a[i].x;
e[++cnt] = a[i].y;
}
sort(e + 1, e + 1 + cnt);
tot = unique(e + 1, e + 1 + cnt) - e - 1;
sort(a + 1, a + k + 1, cmp);
for (int i = 0; i <= tot + 100; i++) {
res[i] = 0;
}
for (int i = 1; i <= k; i++) {
int cur = lower_bound(e + 1, e + 1 + tot, a[i].y) - e;
if (a[i].dir == 'U') {
add(cur, 1);
} else if (a[i].dir == 'D') {
add(1, 1);
add(cur + 1, -1);
} else {
if (a[i].dir == 'L')
ans += query(cur);
}
}
sort(a + 1, a + 1 + k, reserve_cmp);
for (int i = 0; i <= tot + 100; i++) {
res[i] = 0;
}
for (int i = 1; i <= k; i++) {
int cur = lower_bound(e + 1, e + 1 + tot, a[i].y) - e;
if (a[i].dir == 'U') {
add(cur, 1);
} else if (a[i].dir == 'D') {
add(1, 1);
add(cur + 1, -1);
} else {
if (a[i].dir == 'R')
ans += query(cur);
}
}
printf("%d
", ans);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int _;
string s;
int main() {
scanf("%d", &_);
while (_--) {
cin >> s;
int cnt = 0;
for (int i = 0; s[i]; i++) {
if (s[i] == 'z') {
cnt = 1;
break;
}
}
if (!cnt || s[0] < 'y') {
cout << s << endl;
continue;
}
if (s[0] == 'z') {
s[0] = 'b';
cout << s << endl;
continue;
}
if (s[0] == 'y') {
int i = 0;
while (s[i] == 'y') {
i++;
}
for (; s[i]; i++) {
if (s[i] == 'z') {
s[i] = 'b';
break;
} else {
break;
}
}
}
cout << s << endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int n,f,a[200];
bool check(int x,int i,int j,int k) {
for (int ii = 0; ii <= i; ii++) {
for (int jj = 0; jj <= j; jj++) {
for (int kk = 0; kk <= k; kk++) {
if (ii * 10 + jj * 20 + kk * 50 == x) {
return 1;
}
}
}
}
return 0;
}
int main() {
int _;
scanf("%d", &_);
while (_--) {
f = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] % 10) {
f = 1;
}
}
if (f) {
printf("-1
");
continue;
}
int ans = 1900000000;
int cnt = 0;
int tmp;
for (int i = 0; i <= 1; i++) {
for (int j = 0; j <= 4; j++) {
for (int k = 0; k <= 1; k++) {
cnt = 0;
int flag=1;
f = 1;
for (int l = 1; l <= n; l++) {
tmp = a[l];
f = 0;
if (tmp < 100) {
if (check(tmp, i, j, k)) {
continue;
} else flag = 0;
} else {
f = check(tmp % 100 + 100, i, j, k);
if (f)
cnt = max(cnt, (a[l] - 100) / 100);
else if (check(tmp % 100, i, j, k))
cnt = max(cnt, a[l] / 100);
else flag = 0;
}
if (!flag) {
break;
}
}
if (flag) ans = min(ans, i + j + k + cnt);
}
}
}
printf("%d
", ans);
}
return 0;
}