// Arup Guha
// Started on 4/10/14, finished on 5/10/14.
// Solution to 2013 UCF Locals Problem: Longest Increasing Sequence

import java.util.*;
import java.io.*;

public class lis {

	final public static long MOD = 1000000007;
	final public static int MAX = 100001;

	public static int n;
	public static int k;
	public static int[] arr;

	public static void main(String[] args) throws Exception {

		Scanner stdin = new Scanner(new File("lis.in"));
		int numCases = stdin.nextInt();

		// Process each case.
		for (int loop=0; loop<numCases; loop++) {

			// Read in info.
			n = stdin.nextInt();
			k = stdin.nextInt();
			arr = new int[n];
			for (int i=0; i<n; i++)
				arr[i] = stdin.nextInt()+1;

			// Solve and output.
			System.out.println(solve());
		}

		stdin.close();
	}

	public static long solve() {

		// Need to keep track of k trees.
		bit[] trees = new bit[k];
		for (int i=0; i<k; i++)
			trees[i] = new bit(MAX, MOD);

		// Loop through items in the array.
		for (int i=0; i<n; i++) {

			// Go through each sequence length, backwards (just like subset sum, so you don't
			// build off a newly formed sequence.)
			for (int j=k-1; j>=0; j--) {

				// Start a new sequence.
				if (j < k-1) trees[j+1].add(arr[i], trees[j].atOrAbove(arr[i]));

				// Continue all LIS of length k ending at index i.
				long tmp = trees[j].sum(arr[i]-1);
				if (j == 0) tmp++;
				trees[j].add(arr[i], tmp);
			}
		}

		// This is the answer we want.
		return trees[k-1].all();
	}
}

class bit {

	public long[] cumfreq;
	public long MOD;

	// Do indexes 1 to n.
	public bit(int n, long m) {

		int size = 1;
		while (size < n)
			size <<= 1;
		n = size;
		cumfreq = new long[n+1];
		MOD = m;
	}

	// Uses 1 based indexing.
	public void add(int index, long value) {
		while (index < cumfreq.length) {
			cumfreq[index] = (cumfreq[index]+value)%MOD;
			index += Integer.lowestOneBit(index);
		}
	}

	// Return the total number of items in the BIT.
	public long all() {
		return sum(cumfreq.length-1);
	}

	// Return the total number of items in the BIT at or above index.
	public long atOrAbove(int index) {
		long sub = 0;
		if (index > 0) sub = sum(index-1);
		return (all() - sub + MOD)%MOD;
	}

	// Returns the sum of everything upto index.
	public long sum(int index) {
		long ans = 0;
		while (index > 0) {
			ans = (ans + cumfreq[index])%MOD;
			index -= (Integer.lowestOneBit(index));
		}
		return ans;
	}

	// Use 1 based indexing.
	public long sum(int low, int high) {
		return sum(high) - sum(low-1);
	}
}