#!/bin/python3

import math
import os
import random
import re
import sys



if __name__ == '__main__':
    nm = input().split()

    n = int(nm[0])

    m = int(nm[1])

    arr = []

    for _ in range(n):
        arr.append(list(map(int, input().rstrip().split())))

    k = int(input())

    sort = sorted(arr, key=lambda x: x[k])      #arr is a list of lists, we're sorting by the kth element of the lists
    for s in sort:
        string = ''
        for n in s:
            string += str(n)+" "                #create string of space-separated items in s
        print(string)                           #then print that string for every s in sort

