#include <bits/stdc++.h>
using namespace std;
const long long N = 1e3 + 7;
int n, m;
int a[N];
void solve() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 2, a + n + 1);
  int l = 2;
  while (l <= n) {
    if (a[1] + a[l] <= m) {
      a[1] += a[l];
      a[l] = 0;
    } else {
      a[1] = m;
      break;
    }
    ++l;
  }
  cout << a[1] << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
}
