#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, t, i;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    int a[n];
    int mx = 0, s = 0;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      if (i == 0)
        mx = a[i];
      else {
        s += a[i];
      }
    }
    int val = min(m - mx, s);
    cout << val + a[0] << endl;
  }
  return 0;
}
