#include <bits/stdc++.h>
int min(int a, int b) {
  if (a > b)
    return b;
  else
    return a;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m;
    scanf("%d %d", &n, &m);
    int arr[n];
    unsigned long long int sum = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &arr[i]);
      sum += arr[i];
    }
    printf("%d\n", min(sum, m));
  }
}
