#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    int n, m, h;
    cin >> n >> m;
    long long int sum = 0;
    for (int j = 0; j < n; ++j) {
      int x;
      cin >> x;
      if (j != 0) sum = sum + x;
      if (j == 0) h = x;
    }
    if (m - h < sum)
      h = m;
    else
      h = h + sum;
    cout << h << "\n";
  }
}
