#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define yes cout << "Yes" << "\n";
#define no cout << "No" << "\n";
#define fri(a,b) for(ll i = a; i<b; i++)
#define frj(a,b) for(ll j = a; j <b; j++)
#define frk(a,b) for(ll k = a; k <b; k++)
#define rfri(a,b) for(ll i = a; i>=b; i--)
using namespace std;
int main()
{
ios_base:: sync_with_stdio(false);
cin.tie(NULL);
ll T = 1;
cin >> T;
while(T--)
{
ll n,k;
cin >> n >> k ;
ll a[n];
fri(0,n) cin >> a[i];
sort(a,a+n);
ll sum = 0;
fri(0,k)
{
sum += a[i];
}
cout << sum << "\n";
}
}