#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    int arr[n];
    int right = 1;
    for (int i = 0; i < n; i++) cin >> arr[i];
    while (arr[0] < m) {
      if (right == n) break;
      if (arr[right] > 0) {
        arr[right]--;
        arr[0]++;
      } else if (arr[right] == 0)
        right++;
    }
    cout << arr[0] << endl;
  }
}
