You are given an array of *n* integers *a*<sub class="lower-index">1</sub>... *a*<sub class="lower-index">*n*</sub>. The cost of a subsegment is the number of unordered pairs of distinct indices within the subsegment that contain equal elements. Split the given array into *k* non-intersecting non-empty subsegments so that the sum of their costs is minimum possible. Each element should be present in exactly one subsegment.
The first line contains two integers *n* and *k* (2 ≤ *n* ≤ 10<sup class="upper-index">5</sup>, 2 ≤ *k* ≤ *min* (*n*, 20))  — the length of the array and the number of segments you need to split the array into.

The next line contains *n* integers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ *n*) — the elements of the array.
In the first example it's optimal to split the sequence into the following three subsegments: [1], [1, 3], [3, 3, 2, 1]. The costs are 0, 0 and 1, thus the answer is 1.

In the second example it's optimal to split the sequence in two equal halves. The cost for each half is 4.

In the third example it's optimal to split the sequence in the following way: [1, 2, 2, 2, 1], [2, 1, 1, 1, 2], [2, 1, 1]. The costs are 4, 4, 1.
7 3
1 1 3 3 3 2 1
1
10 2
1 2 1 2 1 2 1 2 1 2
8
13 3
1 2 2 2 1 2 1 1 1 2 2 1 1
9
2 2
2 2
0
15 2
11 9 15 15 15 15 15 15 9 9 11 15 9 11 11
15
128 5
116 8 116 116 119 39 116 116 119 116 8 119 119 119 39 116 39 119 39 119 119 39 8 39 8 119 8 116 116 116 119 119 8 39 39 8 116 119 119 119 119 8 8 8 119 39 119 116 119 119 39 39 119 8 116 116 116 116 116 119 116 116 119 116 39 39 119 8 8 119 39 116 39 39 119 119 116 116 119 119 119 119 8 8 116 116 116 39 119 39 119 119 116 119 8 119 8 8 116 39 8 8 116 39 8 39 119 8 8 119 8 119 119 119 8 8 8 116 119 8 8 39 39 8 119 116 119 8
398
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>

using namespace std;
#define INF 0x7FFFFFFFFFFFFFFF
#define ll long long

void solve()
{
        int n;
        cin >> n;
        if(n == 1)
        {
                cout << 0 <<endl;
                return;
        }
        vector<ll> v(n);
        for(auto &it: v)
                cin >> it;
        vector<ll> tmp(1, INF);
        vector<int> Min;
        for(int i = 0; i < v.size(); i++)
        {
                auto it = upper_bound(tmp.begin(), tmp.end(), v[i]);
                if(it == tmp.end())
                {
                        tmp.push_back(v[i]);

                }
                else if(it == tmp.begin())
                {
                        tmp[0] = v[i];
                        Min.push_back(i);
                }
                else
                        *it = v[i];
        }
        ll Max = 0;
        ll Min2 = tmp[1];
        for(int k = 0; k < Min.size(); k++)
        {
                tmp.clear();
                int lb = Min[k];
                if(v[lb] > Min2)
                        continue;
                for(int i = Min[k]; i < v.size(); i++)
                {
                        auto it = upper_bound(tmp.begin(), tmp.end(), v[i]);
                        if(it == tmp.end())
                        {
                                Max = max(v[i] - v[lb], Max);
                                tmp.push_back(v[i]);
                        }
                        else if(it != tmp.begin())
                                *it = v[i];
                }
        }
        cout << Max <<endl;
}


int main()
{
        cin.tie(0);
        cin.sync_with_stdio(0);
        int T;
        cin >> T;
        while(T--)
                solve();
}
