#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 10;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
int main() {
  long long q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long n, m;
    cin >> n >> m;
    long long cnt = 0, sum = 0;
    cin >> cnt;
    for (int j = 1; j < n; j++) {
      long long x;
      cin >> x;
      sum += x;
    }
    cout << cnt + min(m - cnt, sum) << '\n';
  }
}
