#include <bits/stdc++.h>
using namespace std;
int n, m, k, t;
int dr[] = {0, -1, 0, 1};
int dc[] = {-1, 0, 1, 0};
int ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    vector<int> a(n);
    double avg = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      avg += a[i];
    }
    for (int i = m; i >= 0; i--) {
      double tmp = avg;
      if ((tmp - i) >= 0) {
        ans = i;
        break;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
