#include <cstdio>
#include <string>
#include <algorithm>
const int N = int(3e5) + 2;
int n, m, k;
int q[N];
char c[N];
int p[N], p_[N];
int e[N], e_[N];
int cnt[N];
int next[N], next_[N];
std::string ans;
int main()
{
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; i++)
{
scanf("%d %c", q + i, c + i);
next[i] = --q[i];
}
for (int i = 0; i < n; i++)
cnt[c[i]]++;
for (int i = 1; i < 256; i++)
cnt[i] += cnt[i - 1];
for (int i = 0; i < n; i++)
p[--cnt[c[i]]] = i;
for (int i = 1; i < n; i++)
{
e[p[i]] = e[p[i - 1]];
if (c[p[i]] != c[p[i - 1]])
e[p[i]]++;
}
for (int w = 0; w < 20; w++)
{
std::fill(cnt, cnt + n, 0);
for (int i = 0; i < n; i++)
cnt[e[next[i]]]++;
for (int i = 1; i < n; i++)
cnt[i] += cnt[i - 1];
for (int i = 0; i < n; i++)
p_[--cnt[e[next[i]]]] = i;
std::reverse(p_, p_ + n);
std::fill(cnt, cnt + n, 0);
for (int i = 0; i < n; i++)
cnt[e[p_[i]]]++;
for (int i = 1; i < n; i++)
cnt[i] += cnt[i - 1];
for (int i = 0; i < n; i++)
p[--cnt[e[p_[i]]]] = p_[i];
for (int i = 0; i < n; i++)
next_[i] = next[i], e_[i] = e[i];
e[p[0]] = 0;
for (int i = 1; i < n; i++)
{
e[p[i]] = e[p[i - 1]];
if (e_[p[i]] != e_[p[i - 1]] ||
e_[next[p[i]]] != e_[next[p[i - 1]]])
e[p[i]]++;
}
for (int i = 0; i < n; i++)
next[i] = next_[next_[i]];
}
int it = p[k - 1];
for (int i = 0; i < m; i++)
{
ans.push_back(c[it]);
it = q[it];
}
printf("%s", ans.c_str());
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGFsZ29yaXRobT4KCmNvbnN0IGludCBOID0gaW50KDNlNSkgKyAy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