// Arup Guha
// 6/22/2015
// Solution to SI@UCF Competition Camp Contest #4 Problem I: Zigzag Subsequence

import java.util.*;
import java.io.*;

public class zigzag2_arup {

	final public static long MOD = 1000000007L;

	public static void main(String[] args) throws Exception {

		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		int numCases = Integer.parseInt(stdin.readLine());

		// Process each case.
		for (int loop=0; loop<numCases; loop++) {

			int n = Integer.parseInt(stdin.readLine());
			StringTokenizer tok = new StringTokenizer(stdin.readLine());
			TreeSet<Integer> set = new TreeSet<Integer>();
			int[] nums = new int[n];

			// Store sequence and unique items.
			for (int i=0; i<n; i++) {
				nums[i] = Integer.parseInt(tok.nextToken());
				set.add(nums[i]);
			}

			// Compute mapped compressed coordinates.
			HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
			int index = 1;
			while (set.size() > 0) map.put(set.pollFirst(), index++);

			// Remap - this sequence has same answer.
			for (int i=0; i<n; i++)
				nums[i] = map.get(nums[i]);

			// Set up BITs.
			long sub = 0;
			bit up = new bit(index, MOD);
			bit down = new bit(index, MOD);
			bit seqBit = new bit(index, MOD);

			// Go through numbers.
			for (int i=0; i<n; i++) {

				// Calculate previous up and down sequences above and below current #.
				long prevUp = up.above(nums[i]);
				long prevDown = down.below(nums[i]);
				down.add(nums[i], prevUp+1);
				up.add(nums[i], prevDown+1);

				// Count all new sequences of length 1 or 2; we'll sub these out later.
				sub = (sub + 2 + seqBit.above(nums[i]) + seqBit.below(nums[i]))%MOD;

				// Just add this number to our simple bit that keeps track of just the sequence.
				seqBit.add(nums[i], 1);
			}

			// This is our final result!
			long res = (up.all() + down.all() - sub + MOD)%MOD;
			System.out.println(res);
		}
	}
}

class bit {

	public long[] cumfreq;
	public long mod;

	// Do indexes 1 to n.
	public bit(int n, long myMod) {

		int size = 1;
		while (size < n) size <<= 1;
		n = size;

		cumfreq = new long[n+1];
		mod = myMod;
	}

	// 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);
		}
	}

	// 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) + mod)%mod;
	}

	// 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 above index.
	public long above(int index) {
		return (all() - sum(index) + mod)%mod;
	}

	// Return the total number of items in the BIT below index.
	public long below(int index) {
		return sum(index-1);
	}
}