#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    vector<long long> v;
    for (int i = 0; i < n; i++) {
      long long x;
      cin >> x;
      v.push_back(x);
    }
    long long avg = 0;
    for (int i = 0; i < n; i++) {
      avg += v[i];
    }
    long long sum = avg;
    avg /= n;
    long long ans;
    if (sum <= m) {
      ans = sum;
    } else {
      ans = m;
    }
    cout << ans << '\n';
  }
  return 0;
}
