```5 2
aaa 1
aa 2
a 3
ab 3
bb 4
b 2
a 4```

```ab
Orz YYR tql```

## 比赛时

（没想要要用 `char` 的时候我还以为要用 Trie 树或者 hash 来优化内存，我真是个憨憨）

## 代码

```#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;

struct node {
char x[61];
int size, num;
}mz[26][100001];
int n, m, tmpl, num[26], x, size;
char c, tmp[61];

bool cmp(node x, node y) {
if (x.size != y.size) return x.size > y.size;
return x.num < y.num;
}

int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
size = 0;

c = getchar();
while (c < 'a' || c > 'z') c = getchar();
while (c >= 'a' && c <= 'z') {
tmp[size++] = c;
tmpl = c - 'a';
c = getchar();
}
scanf("%d", &x);

num[tmpl]++;
for (int j = 0; j < size; j++) mz[tmpl][num[tmpl]].x[j] = tmp[j];
mz[tmpl][num[tmpl]].size = x;
mz[tmpl][num[tmpl]].num = i;
}

for (int i = 0; i < 26; i++) sort(mz[i] + 1, mz[i] + num[i] + 1, cmp);

for (int i = 1; i <= m; i++) {
c = getchar();
while (c < 'a' || c > 'z') c = getchar();
scanf("%d", &x);
if (num[c - 'a'] < x) printf("Orz YYR tql\n");
else {
for (int j = 0; j < strlen(mz[c - 'a'][x].x); j++) putchar(mz[c - 'a'][x].x[j]);
printf("\n");
}
}

return 0;
}```