#include <bits/stdc++.h>
using namespace std;
const long long int zero = 0LL;
const int N = 1e7;
const long long int oo = 1e5;
const double pi = acos(-1);
long long int n, m, t;
vector<long long int> v;
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> m;
    v.resize(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    for (int i = 1; i < n; i++) {
      if (v[i] + v[0] <= m)
        v[0] += v[i];
      else {
        v[0] = m;
        break;
      };
    }
    cout << v[0] << endl;
    v.clear();
  }
  return 0;
}
