// #define MODULAR_ARITHMETIC
// #define INDEXED_SET

#pragma region
#ifndef LOCAL_DEBUG
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <assert.h>
#include <iomanip>
#define pb push_back
#define mp make_pair
#define f(i, a, b) for (int i = a; i < b; i++)
#define revf(i, b, a) for (int i = b; i >= a; i--)
#define srt(v) sort(v.begin(), v.end())
#define revsrt(v) sort(v.rbegin(), v.rend())
#define x first
#define y second
using namespace std;

#ifdef MODULAR_ARITHMETIC
template <typename T>
T add(T a, T b, T c)
{
	T res = a + b;
	return (res >= c ? res - c : res);
}
template <typename T>
T mod_neg(T a, T b, T c)
{
	T res;
	if (abs(a - b) < c)
		res = a - b;
	else
		res = (a - b) % c;
	return (res < 0 ? res + c : res);
}
template <typename T>
T mul(T a, T b, T c)
{
	long res = (long long)a * b;
	return (res >= c ? res % c : res);
}

template <typename T>
T mulmod(T a, T b, T m)
{
	long long q = (long long)(((long double)a * (long double)b) / (long double)m);
	long long r = a * b - q * m;
	if (r > m)
		r %= m;
	if (r < 0)
		r += m;
	return r;
}
template <typename T>
T expo(T e, T n)
{
	T x = 1, p = e;
	while (n)
	{
		if (n & 1)
			x = x * p;
		p = p * p;
		n >>= 1;
	}
	return x;
}
template <typename T>
T power(T e, T n, T m)
{
	T x = 1, p = e;
	while (n)
	{
		if (n & 1)
			x = mul(x, p, m);
		p = mul(p, p, m);
		n >>= 1;
	}
	return x;
}
template <typename T>
T extended_euclid(T a, T b, T &x, T &y)
{
	T xx = 0, yy = 1;
	y = 0;
	x = 1;
	while (b)
	{
		T q = a / b, t = b;
		b = a % b;
		a = t;
		t = xx;
		xx = x - q * xx;
		x = t;
		t = yy;
		yy = y - q * yy;
		y = t;
	}
	return a;
}
template <typename T>
T mod_inverse(T a, T n)
{
	T x, y, z = 0;
	T d = extended_euclid(a, n, x, y);
	return (d > 1 ? -1 : mod_neg(x, z, n));
}
#endif

#ifdef INDEXED_SET
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#endif

#define sp << ' ' <<
#define endl '\n'
#define precision(x) cout << fixed << setprecision(x);
#define fio                \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);

template <typename T>
ostream &operator<<(ostream &os, vector<pair<T, T>> &v)
{
	int n = v.size();
	for (int i = 0; i < n; i++)
		os << v[i].first sp v[i].second << "\n";
	return os;
}

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
	int n = v.size();
	for (int i = 0; i < n; i++)
		os << v[i] << " ";
	os << endl;
	return os;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
	int n = v.size();
	for (int i = 0; i < n; i++)
		is >> v[i];
	return is;
}

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
#pragma endregion

ll mod = 1e9 + 7;
const int MAX = 2 * 1e5 + 5;

void brute(vll a)
{
	vll s;
	for (auto b : a)
	{
		for (auto c : a)
		{
			s.pb(b + c);
		}
	}
	revsrt(s);
	// cout << s;
	f(i, 0, s.size())
	{
		cout << i + 1 sp s[i] << endl;
	}

	vll pre(s.size());
	pre[0] = s[0];
	f(i, 1, s.size()) pre[i] = pre[i - 1] + s[i];
	// cout << pre;
}

void solvetestcase()
{
	ll n, m;
	cin >> n >> m;
	vll a(n);
	cin >> a;
	revsrt(a);
	// brute(a);

	vll pre(n);
	pre[0] = a[0];
	f(i, 1, n) pre[i] = pre[i - 1] + a[i];

	// cout << pre;
	// cout << a;

	vi freq(MAX);
	for (auto num : a)
		freq[num]++;

	vll pre_freq(MAX);
	pre_freq[0] = freq[0];
	f(i, 1, MAX) pre_freq[i] = pre_freq[i - 1] + freq[i];

	ll ans = 0;
	ll start = 0, end = 2 * a[0];

	if (m == n * n)
	{
		cout << pre[n - 1] * n * 2LL << endl;
		return;
	}

	ll greater = 0, equal = 0;
	while (end != start + 1)
	{
		ll mid = (start + end) / 2;
		greater = 0, equal = 0;
		f(i, 0, n)
		{
			ll num = a[i];
			ll req = mid - num;
			req = max(0LL, req);
			ll req_num = pre_freq[MAX - 1] - pre_freq[req];
			equal += freq[req];
			greater += req_num;
		}
		if (greater < m && m <= greater + equal)
		{
			end = mid;
			break;
		}
		if (greater >= m)
			start = mid;
		else
			end = mid;
	}

	greater = 0, equal = 0, ans = 0;
	f(i, 0, n)
	{
		ll num = a[i];
		ll req = end - num;
		req = max(0LL, req);
		ll req_num = pre_freq[MAX - 1] - pre_freq[req];
		equal += freq[req];
		if (req_num)
		{
			m -= req_num;
			ans += pre[req_num - 1] + num * req_num;
		}
		greater += req_num;
	}
	if (m)
	{
		ans += m * end;
	}
	cout << ans << endl;
}

int main()
{
	fio;
	int t = 1;

	// UNCOMMENT FOR TESTCASES	\
	cin >> t;

	f(T, 1, t + 1)
	{
		// UNCOMMENT FOR CODEJAM,HACKERCUP	\
		cout << "Case #" << T << ": ";
		solvetestcase();
	}
};

/*
    AUTHOR:     KUNAL TAWATIA
    EDUCATION:  INDIAN INSTITUTE OF TECHNOLOGY, JODHPUR
*/

Measured memory_bytes: 4224