 #include <bits/stdc++.h>
      //#define ll long long
      using namespace std;
      #define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
      #define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
      #define ll long long
      #define pb push_back
      #define pll pair<ll,ll>
      #define ff first
      #define ss second
     
      #define N 2000001
      #define M 998244353
      #define INF 1000000000000000
      std::vector<ll> v;

int main()
{
  SPEED;
 ll t;
 cin>>t;

 while(t-->0)
 {
    ll n,k;
    cin>>n>>k;
    ll a[n];
    ll i;
    for(i=0;i<n;i++)
    {
      cin>>a[i];
    }
    sort(a,a+n);ll sum=0;
    for(i=0;i<k;i++)
    {
      sum+=a[i]
    }
    cout<<sum;
 }

}