#include <bits/stdc++.h>
using namespace std;
int a[1001];
int main() {
  int n, t, i, j, k, m;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (i = 0; i < n; i++) cin >> a[i];
    int ans = a[0];
    for (i = 1; i < n; i++) {
      if (ans + a[i] <= m)
        ans += a[i];
      else {
        ans = m;
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
