#include <stdio.h>
int substr(char str1[], char str2[], int index)
{
    int n = 0;
    char* s = str1;
    while (*s++) ++n;
    if (0 <= index && index < n){
        s = str1 + index;
        while(*str2++ = *s++);
        return 1;
    }
    s = "IndexError";
    while (*str2++ = *s++);
    return 0;
}
int main()
{
    int count, i;
    int index[20] = {};
    char str1[20][100] = {};
    char str2[20][100];
    scanf("%d", &count);
    for (i = 0; i < count; ++i){
        scanf("%s", str1[i]);
        scanf("%d", &index[i]);
    }
    for (i = 0; i < count; ++i){
        substr(str1[i], str2[i], index[i] - 1);
        printf("%s\n", str2[i]);
    }
    return 0;
}