#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  for (long long i = 0; i < t; ++i) {
    long long n, m;
    cin >> n >> m;
    vector<long long> vec(n);
    for (long long i = 0; i < n; ++i) cin >> vec[i];
    for (long long i = 1; i < n; ++i) {
      while (vec[0] < m && vec[i] > 0) {
        --vec[i];
        ++vec[0];
      }
    }
    cout << vec[0] << '\n';
  }
  return 0;
}
