#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    long long int n, m, sum = 0, sumb = 0, vala = 0;
    ;
    vector<long long int> arr;
    cin >> n >> m;
    for (int j = 0; j < n; j++) {
      int a;
      cin >> a;
      arr.push_back(a);
      sum += a;
      if (j == 0) {
        vala = a;
      } else {
        sumb += a;
      }
    }
    sum = sum / n;
    int temp;
    if (m - vala <= sumb) {
      temp = m - vala;
      sumb -= temp;
      vala = m;
    } else {
      vala += sumb;
    }
    cout << vala << endl;
  }
  return 0;
}
