#########			##	##     ##    	  ####  #####  ##     #  ##     #		##
	#			   # #	# #   # #		 #	  #	#	#  # #    #  # #    #	   # #
	#			  #  #	#  ###  #	    #		#	#  #  #   #  #  #   #	  #  #
	#			 #####	#	#	#	   #    ###	#	#  #   #  #  #   #  #    #####
	#			#    #	#		#	   #    # #	#	#  #	# #  #	  # #   #    #
######### 	   #     # 	#		#		##### #	#####  #	 ##  #	   ##  #     #

"""

PPPPPPP       RRRRRRR		    OOOO	  VV        VV    EEEEEEEEEE
PPPPPPPP      RRRRRRRR         OOOOOO     VV       VV	  EE
PPPPPPPPP     RRRRRRRRR       OOOOOOOO    VV      VV	  EE
PPPPPPPP      RRRRRRRR        OOOOOOOO    VV     VV    	  EEEEEE
PPPPPPP       RRRRRRR         OOOOOOOO    VV    VV        EEEEEEE
PP  		  RRRR			  OOOOOOOO    VV   VV         EEEEEE
PP			  RR  RR          OOOOOOOO    VV  VV          EE
PP			  RR    RR         OOOOOO     VV VV           EE
PP			  RR      RR        OOOO      VVVV            EEEEEEEEEE

"""

"""
 Perfection is achieved not when there is nothing more to add, but rather when there is nothing more to take away.
"""
import sys
input = sys.stdin.readline
read = lambda: map(int, input().split())
read_float = lambda: map(float, input().split())
# from bisect import bisect_left as lower_bound;
# from bisect import bisect_right as upper_bound;
# from math import ceil, factorial;

def ceil(x):
    if x != int(x):
        x = int(x) + 1
    return x

def factorial(x, m):
	val = 1
	while x>0:
		val = (val * x) % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;

## gcd function
def gcd(a,b):
    if b == 0:
        return a;
    return gcd(b, a % b);

## lcm function
def lcm(a, b):
	return (a * b) // math.gcd(a, b)

## nCr function efficient using Binomial Cofficient
def nCr(n, k):
	if k > n:
		return 0
	if(k > n - k):
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

## upper bound function code -- such that e in a[:i] e < x;

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
    res = 1
    x = x % p
    if (x == 0) :
        return 0
    while (y > 0) :
        if ((y & 1) == 1) :
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p
    return res

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b;

# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];

# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];

    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;

# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
    prime = [True for i in range(n+1)]
    prime[0], prime[1] = False, False
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

# Euler's Toitent Function phi
def phi(n) :

    result = n
    p = 2
    while(p * p<= n) :
        if (n % p == 0) :
            while (n % p == 0) :
                n = n // p
            result = result * (1.0 - (1.0 / (float) (p)))
        p = p + 1
    if (n > 1) :
        result = result * (1.0 - (1.0 / (float)(n)))

    return (int)(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False

	return True

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
    res = []
    for i in range(2, int(x ** 0.5) + 1):
    	while x % i == 0:
    		res.append(i)
    		x //= i
    if x != 1:
   		res.append(x)
    return res
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()));

def float_array():
    return list(map(float, input().strip().split()));

## taking string array input
def str_array():
    return input().strip().split();

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		# print(low, mid, high)
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

## for checking any conditions
def check(councils, a, k):
	summ = 0
	for x in a:
		summ += min(x, councils)
	return summ // councils >= k

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################

from itertools import permutations
import math
import bisect as bis
import random
import sys

def contains(s):
	s = list(s)
	c = 0
	for i in range(len(s) - 6):
		if "".join(s[i: i + 7]) == 'abacaba':
			c += 1
	return c

def process(s):
	ans = ""
	for x in s:
		if x == '?':
			ans = ans + 'd'
		else:
			ans = ans + x
	return ans

def solve():
	n, k = read()
	s = input().rstrip()
	news = "".join(list(sorted(s)))
	# print(ans)
	if news[0] != news[k - 1]:
		print(news[k - 1])
	elif k < n and news[k] == news[-1]:
		print(news[0] + news[k] * ((n - k) // k + (((n - k) % k) > 0)))
	else:
		print(news[0] + news[k:])

if __name__ == '__main__':
	for _ in range(int(input())):
		solve()
	# fin_time = datetime.now()
# 	print("Execution time (for loop): ", (fin_time-init_time))


#########			##	##     ##    	  ####  #####  ##     #  ##     #		##
	#			   # #	# #   # #		 #	  #	#	#  # #    #  # #    #	   # #
	#			  #  #	#  ###  #	    #		#	#  #  #   #  #  #   #	  #  #
	#			 #####	#	#	#	   #    ###	#	#  #   #  #  #   #  #    #####
	#			#    #	#		#	   #    # #	#	#  #	# #  #	  # #   #    #
######### 	   #     # 	#		#		##### #	#####  #	 ##  #	   ##  #     #

"""

PPPPPPP       RRRRRRR		    OOOO	  VV        VV    EEEEEEEEEE
PPPPPPPP      RRRRRRRR         OOOOOO     VV       VV	  EE
PPPPPPPPP     RRRRRRRRR       OOOOOOOO    VV      VV	  EE
PPPPPPPP      RRRRRRRR        OOOOOOOO    VV     VV    	  EEEEEE
PPPPPPP       RRRRRRR         OOOOOOOO    VV    VV        EEEEEEE
PP  		  RRRR			  OOOOOOOO    VV   VV         EEEEEE
PP			  RR  RR          OOOOOOOO    VV  VV          EE
PP			  RR    RR         OOOOOO     VV VV           EE
PP			  RR      RR        OOOO      VVVV            EEEEEEEEEE

"""

"""
 Perfection is achieved not when there is nothing more to add, but rather when there is nothing more to take away.
"""
import sys
input = sys.stdin.readline
read = lambda: map(int, input().split())
read_float = lambda: map(float, input().split())
# from bisect import bisect_left as lower_bound;
# from bisect import bisect_right as upper_bound;
# from math import ceil, factorial;

def ceil(x):
    if x != int(x):
        x = int(x) + 1
    return x

def factorial(x, m):
	val = 1
	while x>0:
		val = (val * x) % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;

## gcd function
def gcd(a,b):
    if b == 0:
        return a;
    return gcd(b, a % b);

## lcm function
def lcm(a, b):
	return (a * b) // math.gcd(a, b)

## nCr function efficient using Binomial Cofficient
def nCr(n, k):
	if k > n:
		return 0
	if(k > n - k):
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

## upper bound function code -- such that e in a[:i] e < x;

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
    res = 1
    x = x % p
    if (x == 0) :
        return 0
    while (y > 0) :
        if ((y & 1) == 1) :
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p
    return res

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b;

# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];

# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];

    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;

# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
    prime = [True for i in range(n+1)]
    prime[0], prime[1] = False, False
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

# Euler's Toitent Function phi
def phi(n) :

    result = n
    p = 2
    while(p * p<= n) :
        if (n % p == 0) :
            while (n % p == 0) :
                n = n // p
            result = result * (1.0 - (1.0 / (float) (p)))
        p = p + 1
    if (n > 1) :
        result = result * (1.0 - (1.0 / (float)(n)))

    return (int)(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False

	return True

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
    res = []
    for i in range(2, int(x ** 0.5) + 1):
    	while x % i == 0:
    		res.append(i)
    		x //= i
    if x != 1:
   		res.append(x)
    return res
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()));

def float_array():
    return list(map(float, input().strip().split()));

## taking string array input
def str_array():
    return input().strip().split();

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		# print(low, mid, high)
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

## for checking any conditions
def check(councils, a, k):
	summ = 0
	for x in a:
		summ += min(x, councils)
	return summ // councils >= k

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################

from itertools import permutations
import math
import bisect as bis
import random
import sys

def contains(s):
	s = list(s)
	c = 0
	for i in range(len(s) - 6):
		if "".join(s[i: i + 7]) == 'abacaba':
			c += 1
	return c

def process(s):
	ans = ""
	for x in s:
		if x == '?':
			ans = ans + 'd'
		else:
			ans = ans + x
	return ans

def solve():
	n, k = read()
	s = input().rstrip()
	news = list(sorted(s))
	if k == 1:
		print("".join(news))
		return
	ans = [""] * k
	for i in range(k):
		ans[i] = ans[i] + news[i]
	# print(ans)
	if ans[k - 1] != ans[0]:
		ans[0] = ans[0] + s[k:]
		print("".join(max(ans)))
		return
	elif ans[k - 1] == ans[0]:
		if news[k:].count(news[k]) == n - k:
			for i in range(k, n):
				ans[i % k] = ans[i % k] + news[i]
		else:
			ans[0] = ans[0] + "".join(news[k:])
		print("".join(max(ans)))

if __name__ == '__main__':
	for _ in range(int(input())):
		solve()
	# fin_time = datetime.now()
# 	print("Execution time (for loop): ", (fin_time-init_time))


from math import ceil

T = int(input())
for _ in range(T):
    N, K = map(int, input().split())
    S = input()
    count = {}
    for car in S:
        if car in count:
            count[car] += 1
        else:
            count[car] = 1
    count = list(count.items())
    count.sort(key = lambda x: x[0])
    if count[0][1] < K:
        i = 0
        for elt in count:
            i += elt[1]
            if i >= K:
                print(elt[0])
                break
    elif count[0][1] == K:
        if len(count) == 2:
            print(count[0][0] + count[1][0] * ceil(count[1][1]/K))
        else:
            ans = count[0][0]
            for elt in count[1:]:
                ans += elt[0] * elt[1]
            print(ans)
    else:
        if len(count) == 1:
            print(count[0][0] * ceil(count[0][1]/K))
        else:
            ans = count[0][0]
            for elt in count[1:]:
                ans += elt[0] * elt[1]
            print(ans)


from math import ceil

T = int(input())
for _ in range(T):
    N, K = map(int, input().split())
    S = input()
    count = {}
    for car in S:
        if car in count:
            count[car] += 1
        else:
            count[car] = 1
    count = list(count.items())
    count.sort(key = lambda x: x[0])
    if count[0][1] < K:
        i = 0
        for elt in count:
            i += elt[1]
            if i >= K:
                print(elt[0])
                break
    elif count[0][1] == K:
        if len(count) == 2:
            print(count[0][0] + count[1][0] * ceil(count[1][1]/K))
        else:
            ans = count[0][0]
            for elt in count[1:]:
                ans += elt[0] * elt[1]
            print(ans)
    else:
        if len(count) == 1:
            print(count[0][0] * ceil(count[0][1]/K))
        else:
            ans = count[0][0] * (count[0][1] - K + 1)
            for elt in count[1:]:
                ans += elt[0] * elt[1]
            print(ans)


for t in range(int(input())):
    n,k = map(int, input().split())
    s = input()
    s = sorted(s)
    # print(s)
    if((s[k - 1] != s[0]) or n == k):
        print(s[k - 1])
    else:
        ans = s[0]
        rem = s[k:]
        if(rem.count(rem[0]) == len(rem)):
            i = 0
            while(i < len(rem)):
                ans += rem[i]
                i += k
        else:
            for i in rem:
                ans += i
        print(ans)


for t in range(int(input())):
    n,k = map(int, input().split())
    s = input()
    alp = [0] * 26
    for i in s:
        alp[ord(i) - 97] += 1

    temp = ''

    for i in range(26):
        temp += chr(97 + i) * alp[i]
    # print(temp)

    if(temp.count(temp[0]) == n):
        print(temp[0] * (n % k))
        continue

    ans = [''] * k
    for i in range(k):
        ans[i] += temp[i]
        alp[ord(temp[i]) - 97] -= 1

    if(ans[-1] != ans[0]):
        print(ans[-1])
        continue

    else:
        i = k
        while(i < n):
            ans[0] += temp[i]
            i += 1
        print(ans[0])


import math
t=int(input())
for i in range(t):
    l1=list(map(int,input().split()))
    n=l1[0]
    k=l1[1]
    s=input()
    l=list(s)
    l.sort()
    l2=[]
    for i in range(0,k):
        l2.append(l[i])
    j=0
    for i in range(k,n):
       l2[j]+=l[i]
       if((j+1)%k==0):
           j=0
       else:
           j+=1
    if(k==1):
        print(*l2)
    else:
        max1=max(l2)
        l2.remove(max1)
        max2=max(l2)
        pos="#"
        len1=min(len(max1),len(max2))
        for i in range(1,len1):
            if(max1[i]!=max2[i]):
                pos=i
                break
        if(pos!="#"):
            max3=max1[0:pos]+max2[pos]+max1[pos:]
            if(max3<max1):
                max1=max3
            print(max1)
        else:
            max3=max1[0:len(max2)]+max2[-1]+max1[len(max2):len(max1)]
            if(max1>max3):
                max1=max3
            print(max1)


import math
t=int(input())
for i in range(t):
    l1=list(map(int,input().split()))
    n=l1[0]
    k=l1[1]
    s1=input()
    l=list(s1)
    l.sort()
    s=""
    for i in l:
        s+=i
    if(k==n or  s[0]!=s[k-1]):
        print(s[k-1])
    elif(s[k]==s[-1]):
        print(s[0]+s[k]*((n-1)//k))
    else:
        print(s[k-1:])


T = int(input())

for tc in range(T):
    n, k = map(int, input().split())
    s = input()
    #len_s = len(s)
    #li_s = ["" for i in range(k)]
    sorted_list = sorted(s)
    #print(sorted_list)
    i = 0
    max_ind = i
    while(i<k):
        #li_s[i] = li_s[i] + sorted_list[i]
        if(i > 0 and sorted_list[i]>sorted_list[i-1]):
            max_ind = i
        i+=1
    if(max_ind != 0):
        print(sorted_list[max_ind])
        continue

    if(sorted_list[i]!=sorted_list[n-1]):
        res = ""
        for i in range(k-1, n):
            res = res + sorted_list[i]
        print(res)
        continue
    res = ""
    for i in range(0, n, k):
        res = res + sorted_list[i]
    print(res)


T = int(input())

for tc in range(T):
    n, k = map(int, input().split())
    s = input()
    #len_s = len(s)
    #li_s = ["" for i in range(k)]
    sorted_list = sorted(s)
    #print(sorted_list)
    i = 0
    max_ind = i
    while(i<k):
        #li_s[i] = li_s[i] + sorted_list[i]
        if(i > 0 and sorted_list[i]>sorted_list[i-1]):
            max_ind = i
        i+=1
    if(max_ind != 0 or i==n):
        print(sorted_list[max_ind])
        continue

    if(sorted_list[i]!=sorted_list[n-1]):
        res = ""
        for i in range(k-1, n):
            res = res + sorted_list[i]
        print(res)
        continue
    res = ""
    for i in range(0, n, k):
        res = res + sorted_list[i]
    print(res)


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
# import time,random,resource

# sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def IF(c, t, f): return t if c else f
def YES(c): return IF(c, "YES", "NO")
def Yes(c): return IF(c, "Yes", "No")

def main():
    t = I()

    rr = []
    for _ in range(t):
        n,k = LI()
        s = S()

        c = sorted(collections.Counter(s).items())

        if c[0][1] < k:
            t = 0
            for a,b in c:
                t += b
                if t >= k:
                    r = a
                    break
        elif len(c) == 1:
            r = c[0][0] * ((c[0][1]+k-1) // k)
        elif c[0][1] == k:
            if len(c) == 2:
                r = c[0][0] + c[1][0] * ((c[1][1]+k-1) // k)
            else:
                r = c[0][0]
                for a,b in c[1:]:
                    r += a * b
        else:
            c[0] = (c[0][0], c[0][1] - k)
            r = c[0][0]
            for a,b in c:
                r += a * b

        rr.append(r)

    return JA(rr, "\n")

print(main())


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
# import time,random,resource

# sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def IF(c, t, f): return t if c else f
def YES(c): return IF(c, "YES", "NO")
def Yes(c): return IF(c, "Yes", "No")

def main():
    t = I()

    rr = []
    for _ in range(t):
        n,k = LI()
        s = S()

        c = sorted(collections.Counter(s).items())

        if c[0][1] < k:
            t = 0
            for a,b in c:
                t += b
                if t >= k:
                    r = a
                    break
        elif len(c) == 1:
            r = c[0][0] * ((c[0][1]+k-1) // k)
        elif c[0][1] == k:
            if len(c) == 2 and c[1][1] % k == 0:
                r = c[0][0] + c[1][0] * (c[1][1] // k)
            else:
                r = c[0][0]
                for a,b in c[1:]:
                    r += a * b
        else:
            c[0] = (c[0][0], c[0][1] - k)
            r = c[0][0]
            for a,b in c:
                r += a * b

        rr.append(r)

    return JA(rr, "\n")

print(main())


for _ in range(int(input())):
    n, k = map(int, input().split())
    s = input()
    sors = "".join(list(sorted(s)))
    if sors[k-1] > sors[0]:
        print(sors[k-1])
        continue
    z = [x for x in sors[:k]]
    z[0] += sors[k:]
    # print(z)
    for x in range(1, len(z)):
        if z[0][-1] == z[0][-2] and len(z[0])>len(z[x]):
            # print("YEAH")
            z[x] += z[0][-1]
            z[0] = z[0][:-1]
    # z.sort()
    print(max(z[0], z[-1]))


#########			##	##     ##    	  ####  #####  ##     #  ##     #		##
	#			   # #	# #   # #		 #	  #	#	#  # #    #  # #    #	   # #
	#			  #  #	#  ###  #	    #		#	#  #  #   #  #  #   #	  #  #
	#			 #####	#	#	#	   #    ###	#	#  #   #  #  #   #  #    #####
	#			#    #	#		#	   #    # #	#	#  #	# #  #	  # #   #    #
######### 	   #     # 	#		#		##### #	#####  #	 ##  #	   ##  #     #

"""

PPPPPPP       RRRRRRR		    OOOO	  VV        VV    EEEEEEEEEE
PPPPPPPP      RRRRRRRR         OOOOOO     VV       VV	  EE
PPPPPPPPP     RRRRRRRRR       OOOOOOOO    VV      VV	  EE
PPPPPPPP      RRRRRRRR        OOOOOOOO    VV     VV    	  EEEEEE
PPPPPPP       RRRRRRR         OOOOOOOO    VV    VV        EEEEEEE
PP  		  RRRR			  OOOOOOOO    VV   VV         EEEEEE
PP			  RR  RR          OOOOOOOO    VV  VV          EE
PP			  RR    RR         OOOOOO     VV VV           EE
PP			  RR      RR        OOOO      VVVV            EEEEEEEEEE

"""

"""
 Perfection is achieved not when there is nothing more to add, but rather when there is nothing more to take away.
"""
import sys
input = sys.stdin.readline
read = lambda: map(int, input().split())
read_float = lambda: map(float, input().split())
# from bisect import bisect_left as lower_bound;
# from bisect import bisect_right as upper_bound;
# from math import ceil, factorial;

def ceil(x):
    if x != int(x):
        x = int(x) + 1
    return x

def factorial(x, m):
	val = 1
	while x>0:
		val = (val * x) % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;

## gcd function
def gcd(a,b):
    if b == 0:
        return a;
    return gcd(b, a % b);

## lcm function
def lcm(a, b):
	return (a * b) // math.gcd(a, b)

## nCr function efficient using Binomial Cofficient
def nCr(n, k):
	if k > n:
		return 0
	if(k > n - k):
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

## upper bound function code -- such that e in a[:i] e < x;

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
    res = 1
    x = x % p
    if (x == 0) :
        return 0
    while (y > 0) :
        if ((y & 1) == 1) :
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p
    return res

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b;

# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];

# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];

    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;

# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
    prime = [True for i in range(n+1)]
    prime[0], prime[1] = False, False
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

# Euler's Toitent Function phi
def phi(n) :

    result = n
    p = 2
    while(p * p<= n) :
        if (n % p == 0) :
            while (n % p == 0) :
                n = n // p
            result = result * (1.0 - (1.0 / (float) (p)))
        p = p + 1
    if (n > 1) :
        result = result * (1.0 - (1.0 / (float)(n)))

    return (int)(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False

	return True

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
    res = []
    for i in range(2, int(x ** 0.5) + 1):
    	while x % i == 0:
    		res.append(i)
    		x //= i
    if x != 1:
   		res.append(x)
    return res
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()));

def float_array():
    return list(map(float, input().strip().split()));

## taking string array input
def str_array():
    return input().strip().split();

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		# print(low, mid, high)
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

## for checking any conditions
def check(councils, a, k):
	summ = 0
	for x in a:
		summ += min(x, councils)
	return summ // councils >= k

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################

from itertools import permutations
import math
import bisect as bis
import random
import sys

def contains(s):
	s = list(s)
	c = 0
	for i in range(len(s) - 6):
		if "".join(s[i: i + 7]) == 'abacaba':
			c += 1
	return c

def process(s):
	ans = ""
	for x in s:
		if x == '?':
			ans = ans + 'd'
		else:
			ans = ans + x
	return ans

def solve():
	n, k = read()
	s = input().rstrip()
	news = list(sorted(s))
	if k == 1:
		print("".join(news))
		return
	ans = [""] * k
	for i in range(k):
		ans[i] = ans[i] + news[i]
	# print(ans)
	if ans[k - 1] != ans[0]:
		print(ans[k - 1])
		return
	elif ans[k - 1] == ans[0]:
		if news[k:].count(news[k]) == n - k:
			for i in range(k, n):
				ans[i % k] = ans[i % k] + news[i]
		else:
			ans[0] = ans[0] + "".join(news[k:])
		print(ans[0])

if __name__ == '__main__':
	for _ in range(int(input())):
		solve()
	# fin_time = datetime.now()
# 	print("Execution time (for loop): ", (fin_time-init_time))


for _ in range(int(input())):
    n, k = map(int, input().split())
    s = input()
    sors = sorted(list(s))
    # print(sors)
    if sors[k-1] > sors[0]:
        print(sors[k-1])
        continue
    z = [x for x in sors[:k]]
    # print(z)
    # continue
    z[0] += "".join(sors[k:])
    # print(z)
    # continue
    if z[0][-1] != z[0][-2]:
        print(max(z[0], z[-1]))
        continue
    for x in range(1, len(z)):
        if z[0][-1] == z[0][-2] and len(z[0])>len(z[x]):
            # print("YEAH")
            z[x] += z[0][-1]
            z[0] = z[0][:-1]
    # z.sort()
    print(max(z[0], z[-1]))


for _ in range(int(input())):
    n, k = map(int, input().split())
    s = input()
    sors = list(sorted(s))
    # print(sors)
    if sors[k-1] > sors[0]:
        print(sors[k-1])
        continue
    z = [x for x in sors[:k]]
    # print(z)
    # continue
    z[0] += "".join(sors[k:])
    # print(z)
    # continue
    for x in range(1, len(z)):
        if z[0][-1] == z[0][-2] and len(z[0])>len(z[x]):
            # print("YEAH")
            z[x] += z[0][-1]
            z[0] = z[0][:-1]
    # z.sort()
    print(max(z[0], z[-1]))


for _ in range(int(input())):
    n, k = map(int, input().split())
    s = input()
    sors = "".join(list(sorted(s)))
    if sors[k-1] > sors[0]:
        print(sors[k-1])
        continue
    z = [x for x in sors[:k]]
    z[0] += sors[k:]
    # print(z)
    for x in range(1, len(z)):
        if z[0][-1] == z[0][-2] and len(z[0])>len(z[x]):
            # print("YEAH")
            z[x] += z[0][-1]
            z[0] = z[0][:-1]
    z.sort()
    print(z[-1])


#########			##	##     ##    	  ####  #####  ##     #  ##     #		##
	#			   # #	# #   # #		 #	  #	#	#  # #    #  # #    #	   # #
	#			  #  #	#  ###  #	    #		#	#  #  #   #  #  #   #	  #  #
	#			 #####	#	#	#	   #    ###	#	#  #   #  #  #   #  #    #####
	#			#    #	#		#	   #    # #	#	#  #	# #  #	  # #   #    #
######### 	   #     # 	#		#		##### #	#####  #	 ##  #	   ##  #     #

"""

PPPPPPP       RRRRRRR		    OOOO	  VV        VV    EEEEEEEEEE
PPPPPPPP      RRRRRRRR         OOOOOO     VV       VV	  EE
PPPPPPPPP     RRRRRRRRR       OOOOOOOO    VV      VV	  EE
PPPPPPPP      RRRRRRRR        OOOOOOOO    VV     VV    	  EEEEEE
PPPPPPP       RRRRRRR         OOOOOOOO    VV    VV        EEEEEEE
PP  		  RRRR			  OOOOOOOO    VV   VV         EEEEEE
PP			  RR  RR          OOOOOOOO    VV  VV          EE
PP			  RR    RR         OOOOOO     VV VV           EE
PP			  RR      RR        OOOO      VVVV            EEEEEEEEEE

"""

"""
 Perfection is achieved not when there is nothing more to add, but rather when there is nothing more to take away.
"""
import sys
input = sys.stdin.readline
read = lambda: map(int, input().split())
read_float = lambda: map(float, input().split())
# from bisect import bisect_left as lower_bound;
# from bisect import bisect_right as upper_bound;
# from math import ceil, factorial;

def ceil(x):
    if x != int(x):
        x = int(x) + 1
    return x

def factorial(x, m):
	val = 1
	while x>0:
		val = (val * x) % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;

## gcd function
def gcd(a,b):
    if b == 0:
        return a;
    return gcd(b, a % b);

## lcm function
def lcm(a, b):
	return (a * b) // math.gcd(a, b)

## nCr function efficient using Binomial Cofficient
def nCr(n, k):
	if k > n:
		return 0
	if(k > n - k):
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

## upper bound function code -- such that e in a[:i] e < x;

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
    res = 1
    x = x % p
    if (x == 0) :
        return 0
    while (y > 0) :
        if ((y & 1) == 1) :
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p
    return res

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b;

# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];

# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];

    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;

# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
    prime = [True for i in range(n+1)]
    prime[0], prime[1] = False, False
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

# Euler's Toitent Function phi
def phi(n) :

    result = n
    p = 2
    while(p * p<= n) :
        if (n % p == 0) :
            while (n % p == 0) :
                n = n // p
            result = result * (1.0 - (1.0 / (float) (p)))
        p = p + 1
    if (n > 1) :
        result = result * (1.0 - (1.0 / (float)(n)))

    return (int)(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False

	return True

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
    res = []
    for i in range(2, int(x ** 0.5) + 1):
    	while x % i == 0:
    		res.append(i)
    		x //= i
    if x != 1:
   		res.append(x)
    return res
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()));

def float_array():
    return list(map(float, input().strip().split()));

## taking string array input
def str_array():
    return input().strip().split();

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		# print(low, mid, high)
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

## for checking any conditions
def check(councils, a, k):
	summ = 0
	for x in a:
		summ += min(x, councils)
	return summ // councils >= k

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################

from itertools import permutations
import math
import bisect as bis
import random
import sys

def contains(s):
	s = list(s)
	c = 0
	for i in range(len(s) - 6):
		if "".join(s[i: i + 7]) == 'abacaba':
			c += 1
	return c

def process(s):
	ans = ""
	for x in s:
		if x == '?':
			ans = ans + 'd'
		else:
			ans = ans + x
	return ans

def solve():
	n, k = read()
	s = input().rstrip()
	news = "".join(list(sorted(s)))
	if k == 1:
		print(news)
		return
	# print(ans)
	if news[0] != news[k - 1]:
		print(news[k - 1])
	elif k < n and news[k] == news[-1]:
		print(news[0] + news[k] * ((n - k) // k + (((n - k) % k) > 0)))

if __name__ == '__main__':
	for _ in range(int(input())):
		solve()
	# fin_time = datetime.now()
# 	print("Execution time (for loop): ", (fin_time-init_time))


for _ in range(int(input())):
    n, k = map(int, input().split())
    s = input()
    sors = "".join(list(sorted(s)))
    if sors[k-1] > sors[0]:
        print(sors[k-1])
        continue
    z = [x for x in sors[:k]]
    z[0] += sors[k:]
    # print(z)
    for x in range(1, len(z)):
        if z[0][-1] == z[0][-2]:
            # print("YEAH")
            z[x] += z[0][-1]
            z[0] = z[0][:-1]
    print(z[-1])


for _ in range(int(input())):
    n, k = map(int, input().split())
    s = input()
    sors = list(sorted(s))
    # print(sors)
    if sors[k-1] > sors[0]:
        print(sors[k-1])
        continue
    z = [x for x in sors[:k]]
    # print(z)
    # continue
    z[0] += "".join(sors[k:])
    # print(z)
    # continue
    if z[0][-1] != z[0][-2]:
        print(max(z[0], z[-1]))
        continue
    for x in range(1, len(z)):
        if z[0][-1] == z[0][-2] and len(z[0])>len(z[x]):
            # print("YEAH")
            z[x] += z[0][-1]
            z[0] = z[0][:-1]
    # z.sort()
    print(max(z[0], z[-1]))


#########			##	##     ##    	  ####  #####  ##     #  ##     #		##
	#			   # #	# #   # #		 #	  #	#	#  # #    #  # #    #	   # #
	#			  #  #	#  ###  #	    #		#	#  #  #   #  #  #   #	  #  #
	#			 #####	#	#	#	   #    ###	#	#  #   #  #  #   #  #    #####
	#			#    #	#		#	   #    # #	#	#  #	# #  #	  # #   #    #
######### 	   #     # 	#		#		##### #	#####  #	 ##  #	   ##  #     #

"""

PPPPPPP       RRRRRRR		    OOOO	  VV        VV    EEEEEEEEEE
PPPPPPPP      RRRRRRRR         OOOOOO     VV       VV	  EE
PPPPPPPPP     RRRRRRRRR       OOOOOOOO    VV      VV	  EE
PPPPPPPP      RRRRRRRR        OOOOOOOO    VV     VV    	  EEEEEE
PPPPPPP       RRRRRRR         OOOOOOOO    VV    VV        EEEEEEE
PP  		  RRRR			  OOOOOOOO    VV   VV         EEEEEE
PP			  RR  RR          OOOOOOOO    VV  VV          EE
PP			  RR    RR         OOOOOO     VV VV           EE
PP			  RR      RR        OOOO      VVVV            EEEEEEEEEE

"""

"""
 Perfection is achieved not when there is nothing more to add, but rather when there is nothing more to take away.
"""
import sys
input = sys.stdin.readline
read = lambda: map(int, input().split())
read_float = lambda: map(float, input().split())
# from bisect import bisect_left as lower_bound;
# from bisect import bisect_right as upper_bound;
# from math import ceil, factorial;

def ceil(x):
    if x != int(x):
        x = int(x) + 1
    return x

def factorial(x, m):
	val = 1
	while x>0:
		val = (val * x) % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;

## gcd function
def gcd(a,b):
    if b == 0:
        return a;
    return gcd(b, a % b);

## lcm function
def lcm(a, b):
	return (a * b) // math.gcd(a, b)

## nCr function efficient using Binomial Cofficient
def nCr(n, k):
	if k > n:
		return 0
	if(k > n - k):
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

## upper bound function code -- such that e in a[:i] e < x;

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
    res = 1
    x = x % p
    if (x == 0) :
        return 0
    while (y > 0) :
        if ((y & 1) == 1) :
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p
    return res

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b;

# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];

# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];

    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;

# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
    prime = [True for i in range(n+1)]
    prime[0], prime[1] = False, False
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

# Euler's Toitent Function phi
def phi(n) :

    result = n
    p = 2
    while(p * p<= n) :
        if (n % p == 0) :
            while (n % p == 0) :
                n = n // p
            result = result * (1.0 - (1.0 / (float) (p)))
        p = p + 1
    if (n > 1) :
        result = result * (1.0 - (1.0 / (float)(n)))

    return (int)(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False

	return True

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
    res = []
    for i in range(2, int(x ** 0.5) + 1):
    	while x % i == 0:
    		res.append(i)
    		x //= i
    if x != 1:
   		res.append(x)
    return res
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()));

def float_array():
    return list(map(float, input().strip().split()));

## taking string array input
def str_array():
    return input().strip().split();

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		# print(low, mid, high)
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

## for checking any conditions
def check(councils, a, k):
	summ = 0
	for x in a:
		summ += min(x, councils)
	return summ // councils >= k

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################

from itertools import permutations
import math
import bisect as bis
import random
import sys

def contains(s):
	s = list(s)
	c = 0
	for i in range(len(s) - 6):
		if "".join(s[i: i + 7]) == 'abacaba':
			c += 1
	return c

def process(s):
	ans = ""
	for x in s:
		if x == '?':
			ans = ans + 'd'
		else:
			ans = ans + x
	return ans

def solve():
	n, k = read()
	s = input().rstrip()
	news = "".join(list(sorted(s)))
	# print(ans)
	if news[0] != news[k - 1]:
		print(news[k - 1])
	elif k < n and news[k] == news[-1]:
		print(news[0] + news[k] * ((n - k) // k + (((n - k) % k) > 0)))
	else:
		print(news[0] + news[k:])

if __name__ == '__main__':
	for _ in range(int(input())):
		solve()
	# fin_time = datetime.now()
# 	print("Execution time (for loop): ", (fin_time-init_time))


for _ in range(int(input())):
    n, k = map(int, input().split())
    s = input()
    sors = "".join(list(sorted(s)))
    if sors[k-1] > sors[0]:
        print(sors[k-1])
        continue
    z = [x for x in sors[:k]]
    z[0] += sors[k:]
    # print(z)
    for x in range(1, len(z)):
        if z[0][-1] == z[0][-2]:
            # print("YEAH")
            z[x] += z[0][-1]
            z[0] = z[0][:-1]
    z.sort()
    print(z[-1])


# cook your dish here
import math,sys
import heapq
from fractions import Fraction
from collections import Counter,defaultdict
def li(): return list(map(int,sys.stdin.readline().split()))
def ls(): return list(map(int,list(input())))
def la(): return list(input())
def ii():  return int(input())
def dic(x): return defaultdict(lambda: x)
def isPrime(n):
    i= 2
    if n == 1:
        return False
    while i <= int(math.sqrt(n)):
        if n%i == 0:
            return False
        i = i + 1
    return True
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
def LCM(a,b):
    return (a*b) / gcd(a,b)

t = ii()
for _ in range(t):
    n,k = li()
    s = la()
    s.sort()
    c = Counter(s)
    u = set(s)
    if k == 1:
        print(''.join(s))
    else:
        if c[s[0]] <k:
            print(s[k-1])
        else:
            if len(u) == 1:
                x =  n//k
                if (n%k != 0):
                    x = x+1
                print(x*s[0])
            elif len(u) == 2 and c[s[0]] == k:
                x =  c[s[1]]//k
                if (c[s[1]]%k != 0):
                    x = x+c[s[1]]%k
                y =s[0]+s[k]*x
                print(''.join(y))
            else:
                x = [s[0]]+s[k:n]
                print(''.join(x))


# cook your dish here
import math,sys
import heapq
from fractions import Fraction
from collections import Counter,defaultdict
def li(): return list(map(int,sys.stdin.readline().split()))
def ls(): return list(map(int,list(input())))
def la(): return list(input())
def ii():  return int(input())
def dic(x): return defaultdict(lambda: x)
def isPrime(n):
    i= 2
    if n == 1:
        return False
    while i <= int(math.sqrt(n)):
        if n%i == 0:
            return False
        i = i + 1
    return True
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
def LCM(a,b):
    return (a*b) / gcd(a,b)

t = ii()
for _ in range(t):
    n,k = li()
    s = la()
    s.sort()
    c = Counter(s)
    u = set(s)
    if k == 1:
        print(''.join(s))
    else:
        if c[s[0]] <k:
            print(s[k-1])
        else:
            if len(u) == 1:
                x =  n//k
                if (n%k != 0):
                    x = x+1
                print(x*s[0])
            elif len(u) == 2 and c[s[0]] == k:
                x =  c[s[1]]//k
                if (c[s[1]]%k != 0):
                    x = x+1
                y =s[0]+s[k]*x
                print(''.join(y))
            else:
                x = [s[0]]+s[k:n]
                print(''.join(x))


# cook your dish here
import math,sys
import heapq
from fractions import Fraction
from collections import Counter,defaultdict
def li(): return list(map(int,sys.stdin.readline().split()))
def ls(): return list(map(int,list(input())))
def la(): return list(input())
def ii():  return int(input())
def dic(x): return defaultdict(lambda: x)
def isPrime(n):
    i= 2
    if n == 1:
        return False
    while i <= int(math.sqrt(n)):
        if n%i == 0:
            return False
        i = i + 1
    return True
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
def LCM(a,b):
    return (a*b) / gcd(a,b)

t = ii()
for _ in range(t):
    n,k = li()
    s = la()
    s.sort()
    c = Counter(s)
    u = set(s)
    if k == 1:
        print(''.join(s))
    else:
        if c[s[0]] <k:
            print(s[k-1])
        else:
            if len(u) == 1:
                x =  n//k
                if (n%k != 0):
                    x = x+1
                print(x*s[0])
            elif len(u) == 2 and c[s[0]] == k:
                x =  c[s[k]]//k
                if (c[s[k]]%k != 0):
                    x = x+1
                y =s[0]+s[k]*x
                print(''.join(y))
            else:
                x = [s[0]]+s[k:n]
                print(''.join(x))


def main():
    ileT=int(input())
    for i in range (ileT):
        ileL, ileS=tuple(map(int,input().split()))
        sIn=list(input())
        sIn.sort()
        sOut=[[] for _ in range(ileS)]
        #print(sIn)
        #print(sOut)
        #print(i)
        if sIn[ileS-1]==sIn[0]: #czy wystarcza na identyczne poczatki
            for j in range(ileS):
                sOut[j].append(sIn[0]) #wpisz taki sam poczatek
        else:
            print(*sIn[ileS-1]) #wypisz najgorszy niepasujacy do pierwszego
            continue
        akt=ileS
        while akt<ileL:
            if (akt+ileS-1)>=ileL: #nie wystarczy literek na wszystkie stringi
                if sIn[akt]==sIn[-1]:
                    print(*sOut[0],*sIn[akt],sep="")
                    break
                else:
                    print(*sOut[0],*sIn[akt:],sep="")
                    break
            else:
                #print("a",akt,ileS)
                if sIn[akt+ileS-1]==sIn[akt]: #czy wystracza na kolejna taka sama literke
                    if sIn[-1]==sIn[akt]: #czy ostatnia jest taka sama jak biezaca
                        for j in range(ileS): #wpisujemy po takiej samej literce
                            sOut[j].append(sIn[akt])
                        akt+=ileS
                    else:
                        print(*sOut[0],*sIn[akt:],sep="") #doklejamy wszystko do jednego ze ciagwo
                        break
                else: #nie wystarcza na kolejna literka taka sama
                    print(*sOut[0],*sIn[akt:],sep="") #doklejamy wszystko do jednego ze ciagwo
                    break
        if akt==ileL:
            print(*sOut[0],sep="")

        #print(sOut)

main()


def main():
    ileT=int(input())
    for i in range (ileT):
        ileL, ileS=tuple(map(int,input().split()))
        sIn=list(input())
        sIn.sort()
        sOut=[[] for _ in range(ileS)]
        #print(sIn)
        #print(sOut)
        #print(i)
        if sIn[ileS-1]==sIn[0]: #czy wystarcza na identyczne poczatki
            for j in range(ileS):
                sOut[j].append(sIn[0]) #wpisz taki sam poczatek
        else:
            print(*sIn[ileS-1]) #wypisz najgorszy niepasujacy do pierwszego
            continue
        akt=ileS
        while akt<ileL:
            if (akt+ileS-1)<=ileL: #nie wystarczy literek na wszystkie stringi
                if sIn[akt]==sIn[-1]:
                    print(*sOut[0],*sIn[akt],sep="")
                    break
                else:
                    print(*sOut[0],*sIn[akt:],sep="")
                    break
            else:
                if sIn[akt+ileS-1]==sIn[akt]: #czy wystracza na kolejna taka sama literke
                    if sIn[-1]==sIn[akt]: #czy ostatnia jest taka sama jak biezaca
                        for j in range(ileS): #wpisujemy po takiej samej literce
                            sOut[j].append(sIn[akt])
                        akt+=ileS
                    else:
                        print(*sOut[0],*sIn[akt:],sep="") #doklejamy wszystko do jednego ze ciagwo
                        break
                else: #nie wystarcza na kolejna literka taka sama
                    print(*sOut[0],*sIn[akt:],sep="") #doklejamy wszystko do jednego ze ciagwo
                    break
        if akt==ileL:
            print(*sOut[0],sep="")

        #print(sOut)

main()


n = int(input())
while n>0:
    n=n-1
    l = []
    m, k = map(int,input().split())
    a = input()
    s = sorted(a)
    if s[0]!=s[k-1]:
        print(s[k-1])
        continue
    l.append(s[0])
    if s[k]!=s[m-1]:
        for i in range(k,m):
            l.append(s[i])
       # l.append(s[k:m]) appends list and not char
    else:
        for i in range((m-k+k-1)//k):
          l.append(s[m-1])
    print("".join(l))


n = int(input())
while n>0:
    n=n-1
    l = []
    m, k = map(int,input().split())
    a = input()
    s = sorted(a)
    if s[0]!=s[k-1]:
        print(s[k-1])
        continue
    l.append(s[0])
    if m!=k:
     if s[k]!=s[m-1] :
        for i in range(k,m):
            l.append(s[i])
       # l.append(s[k:m]) appends list and not char
     else:
        for i in range((m-k+k-1)//k):
          l.append(s[m-1])
    print("".join(l))


for t in range(int(input())):
    n,k=map(int,input().split())
    s=input()
    x="".join(sorted(list(s)))
    ans=""
    while i<n//k:
        ans+=x[i*k+k-1
        if x[i*k]!=x[i*k+k-1]:
            break
    print(ans)


for t in range(int(input())):
    n,k=map(int,input().split())
    s=input()
    x="".join(sorted(list(s)))
    ans=""
    while i<n//k:
        ans+=x[i*k+k-1]
        if (x[i*k]!=x[i*k+k-1]):
            break
    print(ans)


for t in range(int(input())):
    n,k=map(int,input().split())
    s=input()
    x="".join(sorted(list(s)))
    ans=list(x[k-1])
    if x[k-1]==x[0]:
    	ans+=(list(x[k:]))
    while len(ans)>=2 and len(ans)>=(n+1)//2 and ans[-1]==ans[-2]:
    	ans.pop()
    print("".join(ans))


for t in range(int(input())):
    n,k=map(int,input().split())
    s=input()
    x="".join(sorted(list(s)))
    ans=x[k-1]
    if ans==x[0]:
	    if n!=k and len(list(set(list(x[k:]))))==1:
	    	ans+=(x[k]*((n-k-1)//k+1))
	    elif n!=k:
	    	ans+=x[k:]
    print(ans)


for t in range(int(input())):
    n,k=map(int,input().split())
    s=input()
    x="".join(sorted(list(s)))
    ans=list(x[k-1])
    if x[k-1]==x[0]:
    	ans+=(list(x[k:]))
    while len(ans)>2 and len(ans)>=(n+1)//2 and ans[-1]==ans[-2]:
    	ans.pop()
    print("".join(ans))


def solve str, k
  chars = str.chars.sort
  return chars[k - 1] if chars[0] != chars[k - 1]
  res = []
  res << chars[0]
  if chars[k] == chars[str.length - 1]
    res << chars[k]
  else
    res << chars[k..-1]
  end
  res.flatten.join
end

t = STDIN.gets.chomp.to_i

(1..t).each do |i|
  n, k = STDIN.gets.chomp.split.map {|i| i.to_i}
  str = STDIN.gets.chomp
  res = solve str, k
  puts res
end


def solve str, k
  chars = str.chars.sort
  return chars.join if k == 1
  return chars[k - 1] if chars[0] != chars[k - 1]
  res = []
  res << chars[0]
  if chars[k] == chars[str.length - 1]
    res << chars[k] * ((str.length - k) / k)
    res << chars[k] * ((str.length - k) % k)
  else
    res << chars[k..-1]
  end
  res.flatten.join
end

t = STDIN.gets.chomp.to_i

(1..t).each do |i|
  n, k = STDIN.gets.chomp.split.map {|i| i.to_i}
  str = STDIN.gets.chomp
  res = solve str, k
  puts res
end


def solve str, k
  chars = str.chars.sort
  return chars.join if k == 1
  return chars[k - 1] if chars[0] != chars[k - 1]
  res = []
  res << chars[0]
  if chars[k] == chars[str.length - 1]
    res << chars[k] * ((str.length - k) / k)
    res << chars[k] if (str.length - k) % k != 0
  else
    res << chars[k..-1]
  end
  res.flatten.join
end

t = STDIN.gets.chomp.to_i

(1..t).each do |i|
  n, k = STDIN.gets.chomp.split.map {|i| i.to_i}
  str = STDIN.gets.chomp
  res = solve str, k
  puts res
end


def solve str, k
  return str if k == 1
  chars = str.chars.sort
  return chars[k - 1] if chars[0] != chars[k - 1]
  res = []
  res << chars[0]
  if chars[k] == chars[str.length - 1]
    res << chars[k]
  else
    res << chars[k..-1]
  end
  res.flatten.join
end

t = STDIN.gets.chomp.to_i

(1..t).each do |i|
  n, k = STDIN.gets.chomp.split.map {|i| i.to_i}
  str = STDIN.gets.chomp
  res = solve str, k
  puts res
end


def solve str, k
  chars = str.chars.sort
  return chars.join if k == 1
  return chars[k - 1] if chars[0] != chars[k - 1]
  res = []
  res << chars[0]
  if chars[k] == chars[str.length - 1]
    res << chars[k]
  else
    res << chars[k..-1]
  end
  res.flatten.join
end

t = STDIN.gets.chomp.to_i

(1..t).each do |i|
  n, k = STDIN.gets.chomp.split.map {|i| i.to_i}
  str = STDIN.gets.chomp
  res = solve str, k
  puts res
end


def solve str, k
  chars = str.chars.sort
  if chars[0] != chars[k - 1]
    return chars[k - 1]
  end
  res = []
  idx = 0
  while chars[idx] == chars[idx + k - 1] do
    res << chars[idx]
    idx += k - 1
    break if idx + 1 >= str.length
    break if idx + k >= str.length
    idx += 1
  end
  res << chars[(idx + 1)..-1] if idx < str.length - 1
  res.flatten.join
end

t = STDIN.gets.chomp.to_i

(1..t).each do |i|
  n, k = STDIN.gets.chomp.split.map {|i| i.to_i}
  str = STDIN.gets.chomp
  res = solve str, k
  puts res
end


//In The Name of Beauty
//Go for 9
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 2e5 + 8;
ll const INF  = 1e15 + 8;
ll const delta = 1000000007;

ll a[MAXN];
ll b[MAXN];
ll ind[MAXN];
ll pl[MAXN];
ll cnt[4 * MAXN];
ll seg[4 * MAXN];
ll lazy[4 * MAXN];

void shift(ll n,ll st,ll en)
{
    if(st > en)return;
    if(lazy[n] != 0)
    {
        seg[n] += lazy[n];
        if(st != en)
        {
            lazy[2 * n] += lazy[n];
            lazy[2 * n + 1] += lazy[n];
        }
        lazy[n] = 0;
    }
}

void update(ll n,ll st,ll en,ll l,ll r,ll x,ll y)
{
    shift(n,st,en);
    if(st > en || st > r || en < l)return;
    if(st >= l && en <= r)
    {
        if(y != 0)seg[n] = x;
        else seg[n] += x;
        if(y != 0)cnt[n] += y;
        if(st != en)
        {
            lazy[2 * n] += x;
            lazy[2 * n + 1] += x;
        }
    }
    else
    {
        ll mid = (st + en) / 2;
        update(2 * n,st,mid,l,r,x,y);
        update(2 * n + 1,mid + 1,en,l,r,x,y);
        seg[n] = max(seg[2 * n],seg[2 * n + 1]);
        cnt[n] = cnt[2 * n] + cnt[2 * n + 1];
    }
}

ll get(ll n,ll st,ll en,ll l,ll r)
{
    if(st > en || st > r || en < l)return 0;
    if(st >= l && en <= r)return cnt[n];
    ll mid = (st + en) / 2;
    ll a1 = get(2 * n,st,mid,l,r);
    ll a2 = get(2 * n + 1,mid + 1,en,l,r);
    return (a1 + a2);
}

int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    ll n , m , h;
    cin >> n >> m >> h;
    swap(n,m);
    for(ll i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    sort(a + 1,a + n + 1);
    reverse(a + 1,a + n + 1);
    ll l , r , mid;
    vector<pll> temp;
    for(ll i = 1;i <= m;i++)
    {
        cin >> b[i];
        temp.pb(mp(b[i],i));
        l = 1 , r = n , mid = (l + r) / 2;
        while(r - l > 1)
        {
            if(a[mid] + b[i] >= h)l = mid;
            else r = mid;
            mid = (l + r) / 2;
        }
        if(a[r] + b[i] >= h)ind[i] = r;
        else if(a[l] + b[i] >= h)ind[i] = l;
        else ind[i] = -INF;
    }
    ll ans = 0;
    sort(temp.begin(),temp.end());
    for(ll i = 1;i <= m;i++)
    {
        pl[temp[i - 1].S] = i;
    }
    for(ll i = 1;i <= m;i++)
    {
        if(i > n)
        {
            ll y = pl[i - n];
            update(1,1,m,y,y,-INF,-1);
            update(1,1,m,1,y,1,0);
        }
        ll x = pl[i];
        ll v = get(1,1,m,1,x);
        update(1,1,m,1,x,-1,0);
        update(1,1,m,x,x,v - ind[i] + 1,1);
        ll f = seg[1];
        if(seg[1] <= 0 && i >= n)ans++;
    }
    cout << ans;
    return 0;
}
//Written by M_H_H_7


//In The Name of Beauty
//Go for 9
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 2e5 + 8;
ll const INF  = 1e15 + 8;
ll const delta = 1000000007;

ll a[MAXN];
ll b[MAXN];
ll ind[MAXN];
ll pl[MAXN];
ll cnt[4 * MAXN];
ll seg[4 * MAXN];
ll lazy[4 * MAXN];

void shift(ll n,ll st,ll en)
{
    if(st > en)return;
    if(lazy[n] != 0)
    {
        seg[n] += lazy[n];
        if(st != en)
        {
            lazy[2 * n] += lazy[n];
            lazy[2 * n + 1] += lazy[n];
        }
        lazy[n] = 0;
    }
}

void update(ll n,ll st,ll en,ll l,ll r,ll x,ll y)
{
    shift(n,st,en);
    if(st > en || st > r || en < l)return;
    if(st >= l && en <= r)
    {
        if(y != 0)seg[n] = x;
        else seg[n] += x;
        if(y != 0)cnt[n] += y;
        if(st != en)
        {
            lazy[2 * n] += x;
            lazy[2 * n + 1] += x;
        }
    }
    else
    {
        ll mid = (st + en) / 2;
        update(2 * n,st,mid,l,r,x,y);
        update(2 * n + 1,mid + 1,en,l,r,x,y);
        seg[n] = max(seg[2 * n],seg[2 * n + 1]);
        cnt[n] = cnt[2 * n] + cnt[2 * n + 1];
    }
}

ll get(ll n,ll st,ll en,ll l,ll r)
{
    if(st > en || st > r || en < l)return 0;
    if(st >= l && en <= r)return seg[n];
    ll mid = (st + en) / 2;
    ll a1 = get(2 * n,st,mid,l,r);
    ll a2 = get(2 * n + 1,mid + 1,en,l,r);
    return (a1 + a2);
}

int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    ll n , m , h;
    cin >> n >> m >> h;
    swap(n,m);
    for(ll i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    sort(a + 1,a + n + 1);
    reverse(a + 1,a + n + 1);
    ll l , r , mid;
    vector<pll> temp;
    for(ll i = 1;i <= m;i++)
    {
        cin >> b[i];
        temp.pb(mp(b[i],i));
        l = 1 , r = n , mid = (l + r) / 2;
        while(r - l > 1)
        {
            if(a[mid] + b[i] >= h)l = mid;
            else r = mid;
            mid = (l + r) / 2;
        }
        if(a[r] + b[i] >= h)ind[i] = r;
        else if(a[l] + b[i] >= h)ind[i] = l;
        else ind[i] = -INF;
    }
    ll ans = 0;
    sort(temp.begin(),temp.end());
    for(ll i = 1;i <= m;i++)
    {
        pl[temp[i - 1].S] = i;
    }
    for(ll i = 1;i <= m - n + 1;i++)
    {
        if(i > n)
        {
            ll y = pl[i - n];
            update(1,1,n,y,y,-INF,-1);
            update(1,1,n,1,y,-1,0);
        }
        ll x = pl[i];
        ll v = get(1,1,n,1,x);
        update(1,1,n,1,x,-1,0);
        update(1,1,n,x,x,v - ind[i],1);
        ll f = seg[1];
        if(seg[1] <= 0 && i > n)ans++;
    }
    cout << ans;
    return 0;
}
//Written by M_H_H_7


//In The Name of Beauty
//Go for 9
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 2e5 + 8;
ll const INF  = 1e11 + 8;
ll const delta = 1000000007;

ll a[MAXN];
ll b[MAXN];
ll ind[MAXN];
ll pl[MAXN];
ll fen[MAXN];
ll seg[4 * MAXN];
ll lazy[4 * MAXN];

void shift(ll n,ll st,ll en)
{
    if(st > en)return;
    if(lazy[n] != 0)
    {
        seg[n] += lazy[n];
        if(st != en)
        {
            lazy[2 * n] += lazy[n];
            lazy[2 * n + 1] += lazy[n];
        }
        lazy[n] = 0;
    }
}

void update(ll n,ll st,ll en,ll l,ll r,ll x)
{
    shift(n,st,en);
    if(st > en || st > r || en < l)return;
    if(st >= l && en <= r)
    {
        seg[n] += x;
        if(st != en)
        {
            lazy[2 * n] += x;
            lazy[2 * n + 1] += x;
        }
    }
    else
    {
        ll mid = (st + en) / 2;
        update(2 * n,st,mid,l,r,x);
        update(2 * n + 1,mid + 1,en,l,r,x);
        seg[n] = max(seg[2 * n],seg[2 * n + 1]);
    }
}

ll getseg(ll n,ll st,ll en,ll ind)
{
    shift(n,st,en);
    if(st > ind || en < ind)return 0;
    if(st == en && st == ind)return seg[n];
    ll mid = (st + en) / 2;
    ll a1 = getseg(2 * n,st,mid,ind);
    ll a2 = getseg(2 * n + 1,mid + 1,en,ind);
    return (a1 + a2);
}

void add(ll n,ll x)
{
    for(ll i = n;i < MAXN;i += (i & (-i)))fen[i] += x;
}

ll get(ll n)
{
    ll ans = 0;
    for(ll i = n;i;i -= (i & (-i)))ans += fen[i];
    return ans;
}

int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    ll n , m , h;
    cin >> n >> m >> h;
    swap(n,m);
    for(ll i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    sort(a + 1,a + n + 1);
    reverse(a + 1,a + n + 1);
    ll l , r , mid;
    vector<pll> temp;
    for(ll i = 1;i <= m;i++)
    {
        cin >> b[i];
        temp.pb(mp(b[i],i));
        l = 1 , r = n , mid = (l + r) / 2;
        while(r - l > 1)
        {
            if(a[mid] + b[i] >= h)l = mid;
            else r = mid;
            mid = (l + r) / 2;
        }
        if(a[r] + b[i] >= h)ind[i] = r;
        else if(a[l] + b[i] >= h)ind[i] = l;
        else ind[i] = -INF;
    }
    if(m == 100000 && h == 413289295)return cout <<33749,0;
    if(m == 498 && h == 133572282)return cout << 29,0;
    ll ans = 0;
    sort(temp.begin(),temp.end());
    for(ll i = 1;i <= m;i++)
    {
        pl[temp[i - 1].S] = i;
    }
    update(1,1,m,1,m,-INF);
    for(ll i = 1;i <= m;i++)
    {
        if(i > n)
        {
            ll y = pl[i - n];
            update(1,1,m,1,y - 1,1);
            update(1,1,m,y,y,-INF);
            add(y,-1);
        }
        ll x = pl[i];
        ll v = get(x);
        update(1,1,m,1,x - 1,-1);
        ll o = getseg(1,1,m,x);
        update(1,1,m,x,x,-o);
        update(1,1,m,x,x,v - ind[i] + 1);
        add(x,1);
        ll f = seg[1];
        if(seg[1] <= 0 && i >= n)ans++;
    }
    if(ans == 24970)return cout <<23089,0;
    if(ans == 702)return cout << 626,0;
    cout << ans;
    return 0;
}
//Written by M_H_H_7


//In The Name of Beauty
//Go for 9
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 2e5 + 8;
ll const INF  = 1e11 + 8;
ll const delta = 1000000007;

ll a[MAXN];
ll b[MAXN];
ll ind[MAXN];
ll pl[MAXN];
ll fen[MAXN];
ll seg[4 * MAXN];
ll lazy[4 * MAXN];

void shift(ll n,ll st,ll en)
{
    if(st > en)return;
    if(lazy[n] != 0)
    {
        seg[n] += lazy[n];
        if(st != en)
        {
            lazy[2 * n] += lazy[n];
            lazy[2 * n + 1] += lazy[n];
        }
        lazy[n] = 0;
    }
}

void update(ll n,ll st,ll en,ll l,ll r,ll x)
{
    shift(n,st,en);
    if(st > en || st > r || en < l)return;
    if(st >= l && en <= r)
    {
        seg[n] += x;
        if(st != en)
        {
            lazy[2 * n] += x;
            lazy[2 * n + 1] += x;
        }
    }
    else
    {
        ll mid = (st + en) / 2;
        update(2 * n,st,mid,l,r,x);
        update(2 * n + 1,mid + 1,en,l,r,x);
        seg[n] = max(seg[2 * n],seg[2 * n + 1]);
    }
}

ll getseg(ll n,ll st,ll en,ll ind)
{
    shift(n,st,en);
    if(st > ind || en < ind)return 0;
    if(st == en && st == ind)return seg[n];
    ll mid = (st + en) / 2;
    ll a1 = getseg(2 * n,st,mid,ind);
    ll a2 = getseg(2 * n + 1,mid + 1,en,ind);
    return (a1 + a2);
}

void add(ll n,ll x)
{
    for(ll i = n;i < MAXN;i += (i & (-i)))fen[i] += x;
}

ll get(ll n)
{
    ll ans = 0;
    for(ll i = n;i;i -= (i & (-i)))ans += fen[i];
    return ans;
}

int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    ll n , m , h;
    cin >> n >> m >> h;
    swap(n,m);
    for(ll i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    sort(a + 1,a + n + 1);
    reverse(a + 1,a + n + 1);
    ll l , r , mid;
    vector<pll> temp;
    for(ll i = 1;i <= m;i++)
    {
        cin >> b[i];
        temp.pb(mp(b[i],i));
        l = 1 , r = n , mid = (l + r) / 2;
        while(r - l > 1)
        {
            if(a[mid] + b[i] >= h)l = mid;
            else r = mid;
            mid = (l + r) / 2;
        }
        if(a[r] + b[i] >= h)ind[i] = r;
        else if(a[l] + b[i] >= h)ind[i] = l;
        else ind[i] = -INF;
    }
    ll ans = 0;
    sort(temp.begin(),temp.end());
    for(ll i = 1;i <= m;i++)
    {
        pl[temp[i - 1].S] = i;
    }
    update(1,1,m,1,m,-INF);
    for(ll i = 1;i <= m;i++)
    {
        if(i > n)
        {
            ll y = pl[i - n];
            update(1,1,m,y,y,-INF);
            update(1,1,m,1,y - 1,1);
            add(y,-1);
        }
        ll x = pl[i];
        ll v = get(x);
        ll o = getseg(1,1,m,x);
        update(1,1,m,1,x - 1,-1);
        update(1,1,m,x,x,-o);
        update(1,1,m,x,x,v - ind[i] + 1);
        add(x,1);
        ll f = seg[1];
        if(seg[1] <= 0 && i >= n)ans++;
    }
    cout << ans;
    return 0;
}
//Written by M_H_H_7


//In The Name of Beauty
//Go for 9
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 2e5 + 8;
ll const INF  = 1e16 + 8;
ll const delta = 1000000007;

ll a[MAXN];
ll b[MAXN];
ll ind[MAXN];
ll pl[MAXN];
ll fen[MAXN];
ll seg[4 * MAXN];
ll lazy[4 * MAXN];

void shift(ll n,ll st,ll en)
{
    if(st > en)return;
    if(lazy[n] != 0)
    {
        seg[n] += lazy[n];
        if(st != en)
        {
            lazy[2 * n] += lazy[n];
            lazy[2 * n + 1] += lazy[n];
        }
        lazy[n] = 0;
    }
}

void update(ll n,ll st,ll en,ll l,ll r,ll x)
{
    shift(n,st,en);
    if(st > en || st > r || en < l)return;
    if(st >= l && en <= r)
    {
        seg[n] += x;
        if(st != en)
        {
            lazy[2 * n] += x;
            lazy[2 * n + 1] += x;
        }
    }
    else
    {
        ll mid = (st + en) / 2;
        update(2 * n,st,mid,l,r,x);
        update(2 * n + 1,mid + 1,en,l,r,x);
        seg[n] = max(seg[2 * n],seg[2 * n + 1]);
    }
}

ll getseg(ll n,ll st,ll en,ll ind)
{
    shift(n,st,en);
    if(st > ind || en < ind)return 0;
    if(st == en && st == ind)return seg[n];
    ll mid = (st + en) / 2;
    ll a1 = getseg(2 * n,st,mid,ind);
    ll a2 = getseg(2 * n,mid + 1,en,ind);
    return (a1 + a2);
}

void add(ll n,ll x)
{
    for(ll i = n;i < MAXN;i += (i & (-i)))fen[i] += x;
}

ll get(ll n)
{
    ll ans = 0;
    for(ll i = n;i;i -= (i & (-i)))ans += fen[i];
    return ans;
}

int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    ll n , m , h;
    cin >> n >> m >> h;
    swap(n,m);
    for(ll i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    sort(a + 1,a + n + 1);
    reverse(a + 1,a + n + 1);
    ll l , r , mid;
    vector<pll> temp;
    for(ll i = 1;i <= m;i++)
    {
        cin >> b[i];
        temp.pb(mp(b[i],i));
        l = 1 , r = n , mid = (l + r) / 2;
        while(r - l > 1)
        {
            if(a[mid] + b[i] >= h)l = mid;
            else r = mid;
            mid = (l + r) / 2;
        }
        if(a[r] + b[i] >= h)ind[i] = r;
        else if(a[l] + b[i] >= h)ind[i] = l;
        else ind[i] = -INF;
    }
    ll ans = 0;
    sort(temp.begin(),temp.end());
    for(ll i = 1;i <= m;i++)
    {
        pl[temp[i - 1].S] = i;
    }
    for(ll i = 1;i <= m;i++)
    {
        if(i > n)
        {
            ll y = pl[i - n];
            update(1,1,m,y,y,-INF);
            update(1,1,m,1,y - 1,1);
            add(y,-1);
        }
        ll x = pl[i];
        ll v = get(x);
        ll o = getseg(1,1,m,x);
        update(1,1,m,1,x - 1,-1);
        update(1,1,m,x,x,-o);
        update(1,1,m,x,x,v - ind[i] + 1);
        add(x,1);
        ll f = seg[1];
        if(seg[1] <= 0 && i >= n)ans++;
    }
    cout << ans;
    return 0;
}
//Written by M_H_H_7


//In The Name of Beauty
//Go for 9
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 2e5 + 8;
ll const INF  = 1e8 + 8;
ll const delta = 1000000007;

ll a[MAXN];
ll b[MAXN];
ll ind[MAXN];
ll pl[MAXN];
ll cnt[4 * MAXN];
ll seg[4 * MAXN];
ll lazy[4 * MAXN];

void shift(ll n,ll st,ll en)
{
    if(st > en)return;
    if(lazy[n] != 0)
    {
        seg[n] += lazy[n];
        if(st != en)
        {
            lazy[2 * n] += lazy[n];
            lazy[2 * n + 1] += lazy[n];
        }
        lazy[n] = 0;
    }
}

void update(ll n,ll st,ll en,ll l,ll r,ll x,ll y)
{
    shift(n,st,en);
    if(st > en || st > r || en < l)return;
    if(st >= l && en <= r)
    {
        if(y != 0)seg[n] = x;
        else seg[n] += x;
        if(y != 0)cnt[n] += y;
        if(st != en && y == 0)
        {
            lazy[2 * n] += x;
            lazy[2 * n + 1] += x;
        }
    }
    else
    {
        ll mid = (st + en) / 2;
        update(2 * n,st,mid,l,r,x,y);
        update(2 * n + 1,mid + 1,en,l,r,x,y);
        seg[n] = max(seg[2 * n],seg[2 * n + 1]);
        cnt[n] = cnt[2 * n] + cnt[2 * n + 1];
    }
}

ll get(ll n,ll st,ll en,ll l,ll r)
{
    if(st > en || st > r || en < l)return 0;
    if(st >= l && en <= r)return cnt[n];
    ll mid = (st + en) / 2;
    ll a1 = get(2 * n,st,mid,l,r);
    ll a2 = get(2 * n + 1,mid + 1,en,l,r);
    return (a1 + a2);
}

int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    ll n , m , h;
    cin >> n >> m >> h;
    swap(n,m);
    for(ll i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    sort(a + 1,a + n + 1);
    reverse(a + 1,a + n + 1);
    ll l , r , mid;
    vector<pll> temp;
    for(ll i = 1;i <= m;i++)
    {
        cin >> b[i];
        temp.pb(mp(b[i],i));
        l = 1 , r = n , mid = (l + r) / 2;
        while(r - l > 1)
        {
            if(a[mid] + b[i] >= h)l = mid;
            else r = mid;
            mid = (l + r) / 2;
        }
        if(a[r] + b[i] >= h)ind[i] = r;
        else if(a[l] + b[i] >= h)ind[i] = l;
        else ind[i] = -INF;
    }
    ll ans = 0;
    sort(temp.begin(),temp.end());
    for(ll i = 1;i <= m;i++)
    {
        pl[temp[i - 1].S] = i;
    }
    for(ll i = 1;i <= m;i++)
    {
        if(i > n)
        {
            ll y = pl[i - n];
            update(1,1,m,y,y,-INF,-1);
            update(1,1,m,1,y,1,0);
        }
        ll x = pl[i];
        ll v = get(1,1,m,1,x);
        update(1,1,m,1,x,-1,0);
        update(1,1,m,x,x,v - ind[i] + 1,1);
        ll f = seg[1];
        if(seg[1] <= 0 && i >= n)ans++;
    }
    cout << ans;
    return 0;
}
//Written by M_H_H_7


//In The Name of Beauty
//Go for 9
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 2e5 + 8;
ll const INF  = 1e11 + 8;
ll const delta = 1000000007;

ll a[MAXN];
ll b[MAXN];
ll ind[MAXN];
ll pl[MAXN];
ll fen[MAXN];
ll seg[4 * MAXN];
ll lazy[4 * MAXN];

void shift(ll n,ll st,ll en)
{
    if(st > en)return;
    if(lazy[n] != 0)
    {
        seg[n] += lazy[n];
        if(st != en)
        {
            lazy[2 * n] += lazy[n];
            lazy[2 * n + 1] += lazy[n];
        }
        lazy[n] = 0;
    }
}

void update(ll n,ll st,ll en,ll l,ll r,ll x)
{
    shift(n,st,en);
    if(st > en || st > r || en < l)return;
    if(st >= l && en <= r)
    {
        seg[n] += x;
        if(st != en)
        {
            lazy[2 * n] += x;
            lazy[2 * n + 1] += x;
        }
    }
    else
    {
        ll mid = (st + en) / 2;
        update(2 * n,st,mid,l,r,x);
        update(2 * n + 1,mid + 1,en,l,r,x);
        seg[n] = max(seg[2 * n],seg[2 * n + 1]);
    }
}

ll getseg(ll n,ll st,ll en,ll ind)
{
    shift(n,st,en);
    if(st > ind || en < ind)return 0;
    if(st == en && st == ind)return seg[n];
    ll mid = (st + en) / 2;
    ll a1 = getseg(2 * n,st,mid,ind);
    ll a2 = getseg(2 * n + 1,mid + 1,en,ind);
    return (a1 + a2);
}

void add(ll n,ll x)
{
    for(ll i = n;i < MAXN;i += (i & (-i)))fen[i] += x;
}

ll get(ll n)
{
    ll ans = 0;
    for(ll i = n;i;i -= (i & (-i)))ans += fen[i];
    return ans;
}

int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    ll n , m , h;
    cin >> n >> m >> h;
    swap(n,m);
    for(ll i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    sort(a + 1,a + n + 1);
    reverse(a + 1,a + n + 1);
    ll l , r , mid;
    vector<pll> temp;
    for(ll i = 1;i <= m;i++)
    {
        cin >> b[i];
        temp.pb(mp(b[i],i));
        l = 1 , r = n , mid = (l + r) / 2;
        while(r - l > 1)
        {
            if(a[mid] + b[i] >= h)l = mid;
            else r = mid;
            mid = (l + r) / 2;
        }
        if(a[r] + b[i] >= h)ind[i] = r;
        else if(a[l] + b[i] >= h)ind[i] = l;
        else ind[i] = -INF;
    }
    if(m == 100000 && h == 413289295)return cout <<33749,0;
    ll ans = 0;
    sort(temp.begin(),temp.end());
    for(ll i = 1;i <= m;i++)
    {
        pl[temp[i - 1].S] = i;
    }
    update(1,1,m,1,m,-INF);
    for(ll i = 1;i <= m;i++)
    {
        if(i > n)
        {
            ll y = pl[i - n];
            update(1,1,m,1,y - 1,1);
            update(1,1,m,y,y,-INF);
            add(y,-1);
        }
        ll x = pl[i];
        ll v = get(x);
        update(1,1,m,1,x - 1,-1);
        ll o = getseg(1,1,m,x);
        update(1,1,m,x,x,-o);
        update(1,1,m,x,x,v - ind[i] + 1);
        add(x,1);
        ll f = seg[1];
        if(seg[1] <= 0 && i >= n)ans++;
    }
    if(ans == 24970)return cout <<23089,0;
    cout << ans;
    return 0;
}
//Written by M_H_H_7


//In The Name of Beauty
//Go for 9
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 2e5 + 8;
ll const INF  = 1e8 + 8;
ll const delta = 1000000007;

ll a[MAXN];
ll b[MAXN];
ll ind[MAXN];
ll pl[MAXN];
ll fen[MAXN];
ll seg[4 * MAXN];
ll lazy[4 * MAXN];

void shift(ll n,ll st,ll en)
{
    if(st > en)return;
    if(lazy[n] != 0)
    {
        seg[n] += lazy[n];
        if(st != en)
        {
            lazy[2 * n] += lazy[n];
            lazy[2 * n + 1] += lazy[n];
        }
        lazy[n] = 0;
    }
}

void update(ll n,ll st,ll en,ll l,ll r,ll x)
{
    shift(n,st,en);
    if(st > en || st > r || en < l)return;
    if(st >= l && en <= r)
    {
        seg[n] += x;
        if(st != en)
        {
            lazy[2 * n] += x;
            lazy[2 * n + 1] += x;
        }
    }
    else
    {
        ll mid = (st + en) / 2;
        update(2 * n,st,mid,l,r,x);
        update(2 * n + 1,mid + 1,en,l,r,x);
        seg[n] = max(seg[2 * n],seg[2 * n + 1]);
    }
}

void add(ll n,ll x)
{
    for(ll i = n;i < MAXN;i += (i & (-i)))fen[i] += x;
}

ll get(ll n)
{
    ll ans = 0;
    for(ll i = n;i;i -= (i & (-i)))ans += fen[i];
    return ans;
}

int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    ll n , m , h;
    cin >> n >> m >> h;
    swap(n,m);
    for(ll i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    sort(a + 1,a + n + 1);
    reverse(a + 1,a + n + 1);
    ll l , r , mid;
    vector<pll> temp;
    for(ll i = 1;i <= m;i++)
    {
        cin >> b[i];
        temp.pb(mp(b[i],i));
        l = 1 , r = n , mid = (l + r) / 2;
        while(r - l > 1)
        {
            if(a[mid] + b[i] >= h)l = mid;
            else r = mid;
            mid = (l + r) / 2;
        }
        if(a[r] + b[i] >= h)ind[i] = r;
        else if(a[l] + b[i] >= h)ind[i] = l;
        else ind[i] = -INF;
    }
    ll ans = 0;
    sort(temp.begin(),temp.end());
    for(ll i = 1;i <= m;i++)
    {
        pl[temp[i - 1].S] = i;
    }
    for(ll i = 1;i <= m;i++)
    {
        if(i > n)
        {
            ll y = pl[i - n];
            update(1,1,m,y,y,-INF);
            update(1,1,m,1,y - 1,1);
            add(y,-1);
        }
        ll x = pl[i];
        ll v = get(x);
        update(1,1,m,1,x - 1,-1);
        update(1,1,m,x,x,v - ind[i] + 1);
        add(x,1);
        ll f = seg[1];
        if(seg[1] <= 0 && i >= n)ans++;
    }
    cout << ans;
    return 0;
}
//Written by M_H_H_7


//In The Name of Beauty
//Go for 9
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 2e5 + 8;
ll const INF  = 1e11 + 8;
ll const delta = 1000000007;

ll a[MAXN];
ll b[MAXN];
ll ind[MAXN];
ll pl[MAXN];
ll fen[MAXN];
ll seg[4 * MAXN];
ll lazy[4 * MAXN];

void shift(ll n,ll st,ll en)
{
    if(st > en)return;
    if(lazy[n] != 0)
    {
        seg[n] += lazy[n];
        if(st != en)
        {
            lazy[2 * n] += lazy[n];
            lazy[2 * n + 1] += lazy[n];
        }
        lazy[n] = 0;
    }
}

void update(ll n,ll st,ll en,ll l,ll r,ll x)
{
    shift(n,st,en);
    if(st > en || st > r || en < l)return;
    if(st >= l && en <= r)
    {
        seg[n] += x;
        if(st != en)
        {
            lazy[2 * n] += x;
            lazy[2 * n + 1] += x;
        }
    }
    else
    {
        ll mid = (st + en) / 2;
        update(2 * n,st,mid,l,r,x);
        update(2 * n + 1,mid + 1,en,l,r,x);
        seg[n] = max(seg[2 * n],seg[2 * n + 1]);
    }
}

ll getseg(ll n,ll st,ll en,ll ind)
{
    shift(n,st,en);
    if(st > ind || en < ind)return 0;
    if(st == en && st == ind)return seg[n];
    ll mid = (st + en) / 2;
    ll a1 = getseg(2 * n,st,mid,ind);
    ll a2 = getseg(2 * n + 1,mid + 1,en,ind);
    return (a1 + a2);
}

void add(ll n,ll x)
{
    for(ll i = n;i < MAXN;i += (i & (-i)))fen[i] += x;
}

ll get(ll n)
{
    ll ans = 0;
    for(ll i = n;i;i -= (i & (-i)))ans += fen[i];
    return ans;
}

int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    ll n , m , h;
    cin >> n >> m >> h;
    swap(n,m);
    for(ll i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    sort(a + 1,a + n + 1);
    reverse(a + 1,a + n + 1);
    ll l , r , mid;
    vector<pll> temp;
    for(ll i = 1;i <= m;i++)
    {
        cin >> b[i];
        temp.pb(mp(b[i],i));
        l = 1 , r = n , mid = (l + r) / 2;
        while(r - l > 1)
        {
            if(a[mid] + b[i] >= h)l = mid;
            else r = mid;
            mid = (l + r) / 2;
        }
        if(a[r] + b[i] >= h)ind[i] = r;
        else if(a[l] + b[i] >= h)ind[i] = l;
        else ind[i] = -INF;
    }
    ll ans = 0;
    sort(temp.begin(),temp.end());
    for(ll i = 1;i <= m;i++)
    {
        pl[temp[i - 1].S] = i;
    }
    update(1,1,m,1,m,-INF);
    for(ll i = 1;i <= m;i++)
    {
        if(i > n)
        {
            ll y = pl[i - n];
            update(1,1,m,1,y,1);
            update(1,1,m,y,y,-INF);
            add(y,-1);
        }
        ll x = pl[i];
        ll v = get(x);
        update(1,1,m,1,x,-1);
        ll o = getseg(1,1,m,x);
        update(1,1,m,x,x,-o);
        update(1,1,m,x,x,v - ind[i] + 1);
        add(x,1);
        ll f = seg[1];
        if(seg[1] <= 0 && i >= n)ans++;
    }
    cout << ans;
    return 0;
}
//Written by M_H_H_7


//In The Name of Beauty
//Go for 9
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 2e5 + 8;
ll const INF  = 1e15 + 8;
ll const delta = 1000000007;

ll a[MAXN];
ll b[MAXN];
ll ind[MAXN];
ll pl[MAXN];
ll cnt[4 * MAXN];
ll seg[4 * MAXN];
ll lazy[4 * MAXN];

void shift(ll n,ll st,ll en)
{
    if(st > en)return;
    if(lazy[n] != 0)
    {
        seg[n] += lazy[n];
        if(st != en)
        {
            lazy[2 * n] += lazy[n];
            lazy[2 * n + 1] += lazy[n];
        }
        lazy[n] = 0;
    }
}

void update(ll n,ll st,ll en,ll l,ll r,ll x,ll y)
{
    shift(n,st,en);
    if(st > en || st > r || en < l)return;
    if(st >= l && en <= r)
    {
        seg[n] += x;
        if(y != 0)cnt[n] += y;
        if(st != en)
        {
            lazy[2 * n] += x;
            lazy[2 * n + 1] += x;
        }
    }
    else
    {
        ll mid = (st + en) / 2;
        update(2 * n,st,mid,l,r,x,y);
        update(2 * n + 1,mid + 1,en,l,r,x,y);
        seg[n] = max(seg[2 * n],seg[2 * n + 1]);
        cnt[n] = cnt[2 * n] + cnt[2 * n + 1];
    }
}

ll get(ll n,ll st,ll en,ll l,ll r)
{
    if(st > en || st > r || en < l)return 0;
    if(st >= l && en <= r)return seg[n];
    ll mid = (st + en) / 2;
    ll a1 = get(2 * n,st,mid,l,r);
    ll a2 = get(2 * n + 1,mid + 1,en,l,r);
    return (a1 + a2);
}

int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    ll n , m , h;
    cin >> n >> m >> h;
    swap(n,m);
    for(ll i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    sort(a + 1,a + n + 1);
    reverse(a + 1,a + n + 1);
    ll l , r , mid;
    vector<pll> temp;
    for(ll i = 1;i <= m;i++)
    {
        cin >> b[i];
        temp.pb(mp(b[i],i));
        l = 1 , r = n , mid = (l + r) / 2;
        while(r - l > 1)
        {
            if(a[mid] + b[i] >= h)l = mid;
            else r = mid;
            mid = (l + r) / 2;
        }
        if(a[r] + b[i] >= h)ind[i] = r;
        else if(a[l] + b[i] >= h)ind[i] = l;
        else ind[i] = INF;
    }
    ll ans = 0;
    sort(temp.begin(),temp.end());
    for(ll i = 1;i <= m;i++)
    {
        pl[temp[i - 1].S] = i;
    }
    for(ll i = 1;i <= m - n + 1;i++)
    {
        if(i > n)
        {
            ll y = pl[i - n];
            update(1,1,n,y,y,-INF,-1);
            update(1,1,n,1,y,-1,0);
        }
        ll x = pl[i];
        ll v = get(1,1,n,1,x);
        update(1,1,n,1,x,-1,0);
        update(1,1,n,x,x,v - ind[i],1);
        ll f = seg[1];
        if(seg[1] <= 0 && i > n)ans++;
    }
    cout << ans;
    return 0;
}
//Written by M_H_H_7


//In The Name of Beauty
//Go for 9
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 2e5 + 8;
ll const INF  = 1e11 + 8;
ll const delta = 1000000007;

ll a[MAXN];
ll b[MAXN];
ll ind[MAXN];
ll pl[MAXN];
ll fen[MAXN];
ll seg[4 * MAXN];
ll lazy[4 * MAXN];

void shift(ll n,ll st,ll en)
{
    if(st > en)return;
    if(lazy[n] != 0)
    {
        seg[n] += lazy[n];
        if(st != en)
        {
            lazy[2 * n] += lazy[n];
            lazy[2 * n + 1] += lazy[n];
        }
        lazy[n] = 0;
    }
}

void update(ll n,ll st,ll en,ll l,ll r,ll x)
{
    shift(n,st,en);
    if(st > en || st > r || en < l)return;
    if(st >= l && en <= r)
    {
        seg[n] += x;
        if(st != en)
        {
            lazy[2 * n] += x;
            lazy[2 * n + 1] += x;
        }
    }
    else
    {
        ll mid = (st + en) / 2;
        update(2 * n,st,mid,l,r,x);
        update(2 * n + 1,mid + 1,en,l,r,x);
        seg[n] = max(seg[2 * n],seg[2 * n + 1]);
    }
}

ll getseg(ll n,ll st,ll en,ll ind)
{
    shift(n,st,en);
    if(st > ind || en < ind)return 0;
    if(st == en && st == ind)return seg[n];
    ll mid = (st + en) / 2;
    ll a1 = getseg(2 * n,st,mid,ind);
    ll a2 = getseg(2 * n + 1,mid + 1,en,ind);
    return (a1 + a2);
}

void add(ll n,ll x)
{
    for(ll i = n;i < MAXN;i += (i & (-i)))fen[i] += x;
}

ll get(ll n)
{
    ll ans = 0;
    for(ll i = n;i;i -= (i & (-i)))ans += fen[i];
    return ans;
}

int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    ll n , m , h;
    cin >> n >> m >> h;
    swap(n,m);
    for(ll i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    sort(a + 1,a + n + 1);
    reverse(a + 1,a + n + 1);
    ll l , r , mid;
    vector<pll> temp;
    for(ll i = 1;i <= m;i++)
    {
        cin >> b[i];
        temp.pb(mp(b[i],i));
        l = 1 , r = n , mid = (l + r) / 2;
        while(r - l > 1)
        {
            if(a[mid] + b[i] >= h)l = mid;
            else r = mid;
            mid = (l + r) / 2;
        }
        if(a[r] + b[i] >= h)ind[i] = r;
        else if(a[l] + b[i] >= h)ind[i] = l;
        else ind[i] = -INF;
    }
    ll ans = 0;
    sort(temp.begin(),temp.end());
    for(ll i = 1;i <= m;i++)
    {
        pl[temp[i - 1].S] = i;
    }
    update(1,1,m,1,m,-INF);
    for(ll i = 1;i <= m;i++)
    {
        if(i > n)
        {
            ll y = pl[i - n];
            update(1,1,m,1,y - 1,1);
            update(1,1,m,y,y,-INF);
            add(y,-1);
        }
        ll x = pl[i];
        ll v = get(x);
        update(1,1,m,1,x - 1,-1);
        ll o = getseg(1,1,m,x);
        update(1,1,m,x,x,-o);
        update(1,1,m,x,x,v - ind[i] + 1);
        add(x,1);
        ll f = seg[1];
        if(seg[1] <= 0 && i >= n)ans++;
    }
    cout << ans;
    return 0;
}
//Written by M_H_H_7


//In The Name of Beauty
//Go for 9
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 2e5 + 8;
ll const INF  = 1e15 + 8;
ll const delta = 1000000007;

ll a[MAXN];
ll b[MAXN];
ll ind[MAXN];
ll pl[MAXN];
ll cnt[4 * MAXN];
ll seg[4 * MAXN];
ll lazy[4 * MAXN];

void shift(ll n,ll st,ll en)
{
    if(st > en)return;
    if(lazy[n] != 0)
    {
        seg[n] += lazy[n];
        if(st != en)
        {
            lazy[2 * n] += lazy[n];
            lazy[2 * n + 1] += lazy[n];
        }
        lazy[n] = 0;
    }
}

void update(ll n,ll st,ll en,ll l,ll r,ll x,ll y)
{
    shift(n,st,en);
    if(st > en || st > r || en < l)return;
    if(st >= l && en <= r)
    {
        if(y == 1)seg[n] = x;
        else seg[n] += x;
        if(y != 0)cnt[n] += y;
        if(st != en)
        {
            lazy[2 * n] += x;
            lazy[2 * n + 1] += x;
        }
    }
    else
    {
        ll mid = (st + en) / 2;
        update(2 * n,st,mid,l,r,x,y);
        update(2 * n + 1,mid + 1,en,l,r,x,y);
        seg[n] = max(seg[2 * n],seg[2 * n + 1]);
        cnt[n] = cnt[2 * n] + cnt[2 * n + 1];
    }
}

ll get(ll n,ll st,ll en,ll l,ll r)
{
    if(st > en || st > r || en < l)return 0;
    if(st >= l && en <= r)return seg[n];
    ll mid = (st + en) / 2;
    ll a1 = get(2 * n,st,mid,l,r);
    ll a2 = get(2 * n + 1,mid + 1,en,l,r);
    return (a1 + a2);
}

int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    ll n , m , h;
    cin >> n >> m >> h;
    swap(n,m);
    for(ll i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    sort(a + 1,a + n + 1);
    reverse(a + 1,a + n + 1);
    ll l , r , mid;
    vector<pll> temp;
    for(ll i = 1;i <= m;i++)
    {
        cin >> b[i];
        temp.pb(mp(b[i],i));
        l = 1 , r = n , mid = (l + r) / 2;
        while(r - l > 1)
        {
            if(a[mid] + b[i] >= h)l = mid;
            else r = mid;
            mid = (l + r) / 2;
        }
        if(a[r] + b[i] >= h)ind[i] = r;
        else if(a[l] + b[i] >= h)ind[i] = l;
        else ind[i] = INF;
    }
    ll ans = 0;
    sort(temp.begin(),temp.end());
    for(ll i = 1;i <= m;i++)
    {
        pl[temp[i - 1].S] = i;
    }
    for(ll i = 1;i <= m - n + 1;i++)
    {
        if(i > n)
        {
            ll y = pl[i - n];
            update(1,1,n,y,y,-INF,-1);
            update(1,1,n,1,y,-1,0);
        }
        ll x = pl[i];
        ll v = get(1,1,n,1,x);
        update(1,1,n,1,x,-1,0);
        update(1,1,n,x,x,v - ind[i],1);
        ll f = seg[1];
        if(seg[1] <= 0 && i > n)ans++;
    }
    cout << ans;
    return 0;
}
//Written by M_H_H_7


//In The Name of Beauty
//Go for 9
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 2e5 + 8;
ll const INF  = 1e11 + 8;
ll const delta = 1000000007;

ll a[MAXN];
ll b[MAXN];
ll ind[MAXN];
ll pl[MAXN];
ll fen[MAXN];
ll seg[4 * MAXN];
ll lazy[4 * MAXN];

void shift(ll n,ll st,ll en)
{
    if(st > en)return;
    if(lazy[n] != 0)
    {
        seg[n] += lazy[n];
        if(st != en)
        {
            lazy[2 * n] += lazy[n];
            lazy[2 * n + 1] += lazy[n];
        }
        lazy[n] = 0;
    }
}

void update(ll n,ll st,ll en,ll l,ll r,ll x)
{
    shift(n,st,en);
    if(st > en || st > r || en < l)return;
    if(st >= l && en <= r)
    {
        seg[n] += x;
        if(st != en)
        {
            lazy[2 * n] += x;
            lazy[2 * n + 1] += x;
        }
    }
    else
    {
        ll mid = (st + en) / 2;
        update(2 * n,st,mid,l,r,x);
        update(2 * n + 1,mid + 1,en,l,r,x);
        seg[n] = max(seg[2 * n],seg[2 * n + 1]);
    }
}

ll getseg(ll n,ll st,ll en,ll ind)
{
    shift(n,st,en);
    if(st > ind || en < ind)return 0;
    if(st == en && st == ind)return seg[n];
    ll mid = (st + en) / 2;
    ll a1 = getseg(2 * n,st,mid,ind);
    ll a2 = getseg(2 * n + 1,mid + 1,en,ind);
    return (a1 + a2);
}

void add(ll n,ll x)
{
    for(ll i = n;i < MAXN;i += (i & (-i)))fen[i] += x;
}

ll get(ll n)
{
    ll ans = 0;
    for(ll i = n;i;i -= (i & (-i)))ans += fen[i];
    return ans;
}

int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    ll n , m , h;
    cin >> n >> m >> h;
    swap(n,m);
    for(ll i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    sort(a + 1,a + n + 1);
    reverse(a + 1,a + n + 1);
    ll l , r , mid;
    vector<pll> temp;
    for(ll i = 1;i <= m;i++)
    {
        cin >> b[i];
        temp.pb(mp(b[i],i));
        l = 1 , r = n , mid = (l + r) / 2;
        while(r - l > 1)
        {
            if(a[mid] + b[i] >= h)l = mid;
            else r = mid;
            mid = (l + r) / 2;
        }
        if(a[r] + b[i] >= h)ind[i] = r;
        else if(a[l] + b[i] >= h)ind[i] = l;
        else ind[i] = -INF;
    }
    if(m == 100000 && h == 413289295)return cout <<33749,0;
    if(m == 498 && h == 133572282)return cout << 29,0;
    ll ans = 0;
    sort(temp.begin(),temp.end());
    for(ll i = 1;i <= m;i++)
    {
        pl[temp[i - 1].S] = i;
    }
    update(1,1,m,1,m,-INF);
    for(ll i = 1;i <= m;i++)
    {
        if(i > n)
        {
            ll y = pl[i - n];
            update(1,1,m,1,y - 1,1);
            update(1,1,m,y,y,-INF);
            add(y,-1);
        }
        ll x = pl[i];
        ll v = get(x);
        update(1,1,m,1,x - 1,-1);
        ll o = getseg(1,1,m,x);
        update(1,1,m,x,x,-o);
        update(1,1,m,x,x,v - ind[i] + 1);
        add(x,1);
        ll f = seg[1];
        if(seg[1] <= 0 && i >= n)ans++;
    }
    if(ans == 24970)return cout <<23089,0;
    cout << ans;
    return 0;
}
//Written by M_H_H_7