#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int q;
int n, m;
int a[N];
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> q;
  while (q--) {
    cin >> n >> m;
    int t = 0;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      if (i > 0) t += a[i];
    }
    int tmp = m - a[0];
    a[0] += min(tmp, t);
    cout << a[0] << '\n';
  }
  return 0;
}
