$n$ students are taking an exam. The highest possible score at this exam is $m$. Let $a_{i}$ be the score of the $i$-th student. You have access to the school database which stores the results of all students.

You can change each student's score as long as the following conditions are satisfied:   All scores are integers  $0 \leq a_{i} \leq m$  The average score of the class doesn't change. 

You are student $1$ and you would like to maximize your own score.

Find the highest possible score you can assign to yourself such that all conditions are satisfied.


-----Input-----

Each test contains multiple test cases. 

The first line contains the number of test cases $t$ ($1 \le t \le 200$). The description of the test cases follows.

The first line of each test case contains two integers $n$ and $m$ ($1 \leq n \leq 10^{3}$, $1 \leq m \leq 10^{5}$)  — the number of students and the highest possible score respectively.

The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($ 0 \leq a_{i} \leq m$)  — scores of the students.


-----Output-----

For each testcase, output one integer  — the highest possible score you can assign to yourself such that both conditions are satisfied._


-----Example-----
Input
2
4 10
1 2 3 4
4 5
1 2 3 4

Output
10
5



-----Note-----

In the first case, $a = [1,2,3,4] $, with average of $2.5$. You can change array $a$ to $[10,0,0,0]$. Average remains $2.5$, and all conditions are satisfied.

In the second case, $0 \leq a_{i} \leq 5$. You can change $a$ to $[5,1,1,3]$. You cannot increase $a_{1}$ further as it will violate condition $0\le a_i\le m$.

Difficulty: EASY

Solutions:
for _ in range(int(input())):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	l = [int(x) for x in input().split()]
	if sum(l) >= m:
		print(m)
	else:
		print(sum(l))


t = int(input())
for i in range(t):
	(n, m) = [int(k) for k in input().split()]
	mylist = [int(k) for k in input().split()]
	l = len(mylist)
	sum1 = 0
	for i in range(l):
		sum1 = sum1 + mylist[i]
	if sum1 == m:
		print(m)
	elif m > sum1:
		print(sum1)
	elif m < sum1:
		print(m)


t = int(input())
for j in range(t):
	(n, m) = map(int, input().split())
	sum = 0
	for i in list(map(int, input().split())):
		if sum + i <= m:
			sum += i
		else:
			sum = m
	print(sum)


testCases = int(input())
for i1 in range(testCases):
	parameters = list(map(int, input().split()))
	scores = list(map(int, input().split()))
	total = sum(scores)
	print(min(total, parameters[1]))


for _ in range(int(input())):
	(n, m) = [int(u) for u in input().split()]
	li = [int(i) for i in input().split()]
	print(m if sum(li) >= m else sum(li))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split(' '))
	arr = list(map(int, input().split()))
	s = 0
	for i in range(n):
		s = s + arr[i]
	print(min(s, m))


def inplst():
	return list(map(int, input().split()))
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = inplst()
	print(min(sum(l), m))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	print(min(m, a[0] + sum(a[1:])))


from math import *
T = int(input())
while T:
	T -= 1
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) >= m:
		print(m)
	else:
		print(sum(a))


t = int(input())
for i in range(t):
	(n, m) = [int(i) for i in input().split()]
	students = [int(i) for i in input().split()]
	soma = 0
	for i in students:
		soma += i
	print(min(m, soma))


t = int(input())

def find(n, m, s):
	r = 0
	for (ind, c) in enumerate(s):
		if ind == 0:
			continue
		r += c
	res = s[0] + r
	if res <= m:
		print(res)
	else:
		print(m)
for i in range(t):
	(n, m) = map(int, input().split())
	s = [int(x) for x in input().split()]
	find(n, m, s)


def main():
	from sys import stdin, stdout
	for _ in range(int(stdin.readline())):
		(n, m) = map(int, stdin.readline().split())
		arr = list(map(int, stdin.readline().split()))
		minim = min(m - arr[0], sum(arr) - arr[0])
		stdout.write(str(arr[0] + minim) + '\n')
main()


for i in range(int(input())):
	print(min(list(map(int, input().split()))[1], sum(list(map(int, input().split())))))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	marks = 0
	for i in range(0, n):
		marks += arr[i]
	print(min(marks, m))


n = int(input())
for i in range(n):
	(n, m) = map(int, input().split())
	a = map(int, input().split())
	print(min(sum(a), m))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [int(i) for i in input().split()]
	s = sum(a)
	if s > m:
		print(m)
	else:
		print(s)


t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	x = list(map(int, input().split()))
	print(min(sum(x), b))


R = lambda : [*map(int, input().split())]
exec(R()[0] * 'print(min(R()[1],sum(R())));')


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = sum(a)
	if b < m:
		print(b)
	else:
		print(m)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	print(min(s, m))


for i in ' ' * int(input()):
	(n, m) = map(int, input().split())
	L = list(map(int, input().split()))
	if m > sum(L):
		print(sum(L))
	else:
		print(m)


t = int(input())
for i in range(t):
	l1 = list(map(int, input().split()))
	n = l1[0]
	m = l1[1]
	l = list(map(int, input().split()))
	avg = sum(l) / n
	a = l[1:n + 1]
	s = sum(a)
	b = m - l[0]
	t = True
	while t:
		if b <= s:
			print(m)
			t = False
		else:
			m = m - 1
			b = b - 1


rr = lambda : map(int, input().split(' '))
(t,) = rr()
for i in range(t):
	(n, m) = rr()
	nums = rr()
	ans = min(m, sum(nums))
	print(ans)


t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l) - l[0]
	print(min(y, s + l[0]))


t = int(input())
while t > 0:
	z = 0
	n = input()
	(n, m) = n.split()
	ar = input()
	ar = ar.split()
	for i in ar:
		i = int(i)
		z += i
	print(min(int(m), z))
	t -= 1


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().strip().split()))
	if sum(a) > m:
		print(m)
	elif sum(a) <= m:
		print(sum(a))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	x = list(map(int, input().split()))
	if sum(x) >= m:
		print(m)
	elif sum(x) < m:
		print(sum(x))


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	total = int(sum(l) - l[0])
	if l[0] + total <= b:
		print(l[0] + total)
	else:
		print(b)


t = int(input())
while t > 0:
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	sum = 0
	for i in y:
		sum = sum + i
	avg = sum / x[0]
	if x[1] / x[0] <= avg:
		print(int(x[1]))
	else:
		print(sum)
	t = t - 1


t = int(input())
num = list()
score = list()
for j in range(t):
	num.append(list(map(int, input().split())))
	score.append(list(map(int, input().split())))
for j in range(t):
	if sum(score[j]) >= num[j][1]:
		print(num[j][1])
	else:
		print(sum(score[j]))


x = int(input())
for i in range(0, x):
	(n, m) = [int(a) for a in input().split()]
	d = list(map(int, input().split()))[:n]
	k = sum(d)
	if n == 1:
		print(d[0])
	elif m > k:
		print(k)
	else:
		print(m)


no = int(input())
res = []
for i in range(no):
	(n, m) = map(int, input().split())
	marks = list(map(int, input().split()))
	main = min(m, marks[0] + sum(marks[1:n]))
	res.append(main)
for i in res:
	print(i)


def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		x = list(map(int, input().split()))
		remaining_score = sum(x) - x[0]
		if x[0] < m and remaining_score > 0:
			max_ext = min(m - x[0], remaining_score)
			x[0] += max_ext
			remaining_score -= max_ext
		print(x[0])
main()


t = int(input())
for _ in range(t):
	(n, mx) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	my = arr[0]
	their = sum(arr[1:])
	if their >= mx - my:
		print(mx)
	else:
		print(my + their)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	avg = sum(a)
	if m > avg:
		print(avg)
	else:
		print(m)


import math

def ans(l, b):
	sum = 0
	m = 0
	for i in range(0, len(l), 1):
		sum += int(l[i])
		m = min(b, sum)
	print(m)
t = int(input())
while t > 0:
	k = []
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	ans(l, b)
	t -= 1


t = int(input())
for _ in range(t):
	(u, v) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(1, u):
		ans += a[i]
	if a[0] + ans >= v:
		print(v)
	else:
		print(a[0] + ans)


t = int(input())
for i in range(t):
	(a, b) = input().strip().split(' ')
	(a, b) = [int(a), int(b)]
	c = list(map(int, input().strip().split(' ')))
	x = c[0]
	f = sum(c)
	print(min(b, f))


from sys import stdin

def solve(a, m):
	(ans, _sum) = (a[0], sum(a[1:]))
	if len(a) > 1:
		ans = min(m, a[0] + _sum)
	return ans

def main():
	t = int(stdin.readline().strip())
	for _ in range(t):
		(n, m) = map(int, stdin.readline().strip().split())
		a = [int(x) for x in stdin.readline().strip().split()]
		print(solve(a, m))
main()


a = int(input())
for _ in range(a):
	b = input().split()
	max = int(b[1])
	c = input().split()
	sum = 0
	for i in c:
		sum += int(i)
	if sum > max:
		print(max)
	else:
		print(sum)


import sys

def main():
	inp = sys.stdin.read().strip().split('\n')
	out = []
	for j in range(1, len(inp), 2):
		(_, m) = map(int, inp[j].split())
		out.append(min(sum(map(int, inp[j + 1].split())), m))
	return out
print(*main(), sep='\n')


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(n, m) = inputnums()
	a = inputlist()
	total = 0
	for i in range(n):
		total += a[i]
	print(min(m, total))


import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	if sum(a) >= m:
		print(m)
	else:
		print(sum(a))


t = int(input())
for T in range(t):
	nm = input().split()
	mark0 = input().split()
	mark = list(map(int, mark0))
	S = sum(mark)
	aver = S / len(mark)
	if int(nm[1]) - S >= 0:
		print(S)
	else:
		print(nm[1])


T = int(input())
for t in range(T):
	(n, m) = tuple(map(int, input().split()))
	iarr = tuple(map(int, input().split()))
	print(min(m, sum(iarr)))


import math
q = int(input())
for _ in range(q):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	print(min(x, s))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	print(min(s, m))


t = int(input())
for test in range(t):
	(n, m) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	sum = 0
	for i in A:
		sum += i
	if sum >= m:
		print(m)
	else:
		print(sum)


for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	tot = sum(arr)
	print(min(tot, k))


T = int(input())
while T > 0:
	T -= 1
	(n, m) = map(int, input().split())
	L = list(map(int, input().split()))
	num = sum(L)
	if num >= m:
		print(m)
	else:
		print(num)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	x = list(map(int, input().split()))
	s = sum(x)
	if s > m:
		print(m)
	else:
		print(s)


for _ in range(int(input())):
	m = int(input().split()[1])
	arr = list(map(int, input().split()))
	print(min(sum(arr[1:]) + arr[0], m))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	li = list(map(int, input().split()))
	k = sum(li)
	print(min(m, k))


import sys
s = list(map(int, sys.stdin.read().split()))
(t, q, L) = (s[0], 1, [])
for x in range(t):
	p = q + 2
	q = p + s[q]
	m = s[p - 1]
	L.append(sum(s[p:q]))
	if L[x] >= m:
		print(m)
	elif L[x] < m:
		print(L[x])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	mera_score = arr[0]
	for i in range(1, n):
		if arr[i] > 0:
			mera_score += arr[i]
			if mera_score >= m:
				mera_score = m
				break
	print(mera_score)


t = int(input())

def cast(arr):
	arr2 = []
	for i in range(0, len(arr)):
		n = int(arr[i])
		arr2.append(n)
	return arr2

def sum(array):
	num = 0
	for i in range(0, len(array)):
		num += array[i]
	return num
for i in range(0, t):
	inp = input()
	arr = inp.split()
	n = int(arr[0])
	m = int(arr[1])
	inp2 = input()
	a0 = inp2.split()
	a = cast(a0)
	score = a[0]
	average = sum(a) / n
	if sum(a) > m:
		print(m)
	else:
		print(sum(a))


t = int(input())
while t:
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	if s == m:
		a[0] = m
		if n != 1:
			for i in range(1, n):
				a[i] = 0
	elif s > m:
		a[0] = m
		if n != 1:
			a[1] = s - m
			for i in range(2, n):
				a[i] = 0
	else:
		a[0] = s
		if n != 1:
			for i in range(1, n):
				a[i] = 0
	print(a[0])
	t -= 1


t = int(input())
for i in range(0, t):
	(n, m) = [int(x) for x in input().split()]
	a = list(map(int, input().split()))
	print(min(sum(a), m))


from bisect import bisect_left, bisect_right, insort
import sys
import heapq
from math import *
from collections import defaultdict as dd
from collections import deque

def data():
	return sys.stdin.readline().strip()

def mdata():
	return map(int, data().split())
for i in range(int(data())):
	(n, m) = mdata()
	a = list(mdata())
	s = sum(a)
	s -= a[0]
	print(min(m, a[0] + s))


for _ in range(int(input())):
	(a, b) = [int(h) for h in input().split(' ')]
	arr = [int(h) for h in input().split(' ')]
	summ = sum(arr)
	if summ > b:
		print(b)
	else:
		print(summ)


t = int(input())
for i in range(t):
	(n, m) = [int(elem) for elem in input().split()]
	a = [int(elem) for elem in input().split()]
	summ = sum(a) - a[0]
	print(min(m, summ + a[0]))


t = input()
t = int(t)
for _ in range(t):
	average = 0
	total = 0
	average2 = 0
	others = 0
	maxmark = 0
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	a = input().split()
	for q in range(len(a)):
		a[q] = int(a[q])
		total += a[q]
	for q in range(1, len(a)):
		others += a[q]
	ok = False
	while not ok:
		if m - a[0] - others <= 0:
			maxmark = m
			ok = True
		else:
			m -= 1
	print(maxmark)


t = int(input())
for i in range(t):
	(n, m) = [int(x) for x in input().split()]
	scores = [int(x) for x in input().split()]
	s1 = scores[0]
	scores = scores[1:]
	total = sum(scores)
	result = min(s1 + total, m)
	print(result)


kl = int(input())
for l in range(kl):
	(n, m) = [int(i) for i in input().split()]
	s = [int(i) for i in input().split()]
	sm = 0
	for i in range(n):
		sm += s[i]
	if sm <= m:
		print(sm)
	else:
		print(m)


import math
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	print(min(m, sum(a)))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	total = sum(a)
	if m <= total:
		print(m)
	else:
		print(total)


t = int(input())
while t:
	l1 = [int(i) for i in input().split()]
	l2 = [int(i) for i in input().split()]
	av = sum(l2)
	if av - l1[1] >= 0:
		print(l1[1])
	else:
		print(av)
	t -= 1


t = int(input())
for i in range(t):
	(n, m) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	if m < sum(a):
		print(m)
	else:
		print(sum(a))


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
import bisect as bi
import heapq

def I():
	return int(input())

def In():
	return map(int, input().split())

def main():
	try:
		for _ in range(I()):
			(n, m) = In()
			l = list(In())
			t = sum(l)
			if m <= sum(l):
				print(m)
			else:
				print(sum(l))
	except:
		pass
M = 998244353
P = 1000000007
main()


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().strip().split()))
	a = list(map(int, input().strip().split()))
	for i in range(1, len(a)):
		razlika = m - a[0]
		vzamem = a[i]
		if razlika < vzamem:
			a[0] = m
			a[i] -= razlika
		else:
			a[0] += vzamem
			a[i] -= vzamem
	print(a[0])


import sys
inp = sys.stdin.readline

def input():
	return inp().strip()

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

def main():
	T = iin()
	while T:
		T -= 1
		(n, m) = lin()
		a = lin()
		ans = sum(a)
		print(min(ans, m))
main()


t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().split()))
	a = map(int, input().split())
	b = sum(a)
	print(min(m, b))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	print(min(m, sum(A)))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = 0
	for i in range(1, n):
		s += a[i]
	score = min(s, m)
	print(min(a[0] + score, m))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	print(min([sum(a), m]))


t = int(input())
for i in range(t):
	p = input().split()
	n = int(p[0])
	m = int(p[1])
	a = input().split()
	s = 0
	for i in range(len(a)):
		s += int(a[i])
	if s >= m:
		print(m)
	else:
		print(s)


import sys
input = sys.stdin.readline
tc = int(input())
for _ in range(tc):
	(n, m) = map(int, input().split())
	x = [*map(int, input().split())]
	k = x[0]
	a = sum((i for i in x[1:]))
	print(min(m, k + a))


testcases = int(input())
for i in range(testcases):
	(n, m) = list(map(int, input().split()))
	sm = list(map(int, input().split()))
	high_score = 0
	s = sum(sm)
	if s >= m:
		high_score = m
	else:
		high_score = sum(sm)
	print(high_score)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	s = 0
	l = list(map(int, input().split()))
	for j in range(1, a):
		s += l[j]
	print(min(b, l[0] + s))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	ts = sum(arr)
	if ts >= m:
		print(m)
	elif ts < m:
		print(ts)


a = int(input())
for _ in range(a):
	(n, m) = tuple(map(int, input().split(' ')))
	numbers = list(map(int, input().split(' ')))
	s = sum(numbers[1:])
	print(min(numbers[0] + s, m))


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	(n, m) = list(map(int, stdin.readline().strip().split()))
	a = list(map(int, stdin.readline().strip().split()))
	s1 = sum(a[1:])
	if s1 >= m:
		stdout.write(str(m) + '\n')
	elif a[0] + s1 >= m:
		stdout.write(str(m) + '\n')
	else:
		stdout.write(str(a[0] + s1) + '\n')


for i in range(int(input())):
	(n, m) = map(int, input().split())
	marks = list(map(int, input().split()))
	if marks[0] < m:
		val = sum(marks[1:])
		if val >= m or marks[0] + val >= m:
			print(m)
		else:
			print(marks[0] + val)
	else:
		print(marks[0])


import statistics
for i in range(int(input())):
	(a, b) = input().split()
	li = list(map(int, input().split()))
	x = statistics.mean(li)
	y = int(b) / len(li)
	if y <= x:
		print(int(b))
	else:
		while y > x:
			b = int(b) - 1
			y = int(b) / len(li)
		print(int(b))


for t in range(int(input())):
	(n, m) = map(int, input().split())
	score = list(map(int, input().split()))
	c = 0
	i = 1
	while c <= m and i < n:
		c += score[i]
		i += 1
	print(min(c + score[0], m))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	r = sum(l)
	print(min(r, m))


from sys import stdin, gettrace
if not gettrace():

	def input():
		return next(stdin)[:-1]

def main():

	def solve():
		(n, m) = map(int, input().split())
		tot = sum((int(a) for a in input().split()))
		print(min(m, tot))
	q = int(input())
	for _ in range(q):
		solve()
main()


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(min(sum(arr), m))


t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	y = list(map(int, input().split()))
	y = sum(y)
	if y <= l[1]:
		print(y)
	else:
		print(l[1])


import sys
import copy
input = sys.stdin.readline
from math import *
t = int(input())
while t > 0:
	t -= 1
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	print(min(sum(a), m))


t = int(input(''))
for k in range(0, t):
	(a, b) = input('').split(' ')
	n = int(a)
	m = int(b)
	l = input('').split(' ')
	sum = 0
	for i in range(0, len(l)):
		q = l[i]
		g = int(q)
		l[i] = g
		sum = sum + l[i]
	if sum <= m:
		print(sum)
	else:
		print(m)


from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from functools import *
from itertools import permutations, combinations, groupby
import sys
import bisect
import string
import math
import time
import random

def Golf():
	(*a,) = map(int, open(0))

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def I():
	return int(input())

def MI():
	return map(int, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoI():
	return [ord(i) - 97 for i in input()]

def ItoS(nn):
	return chr(nn + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def GI(V, E, Directed=False, index=0):
	org_inp = []
	g = [[] for i in range(n)]
	for i in range(E):
		inp = LI()
		org_inp.append(inp)
		if index == 0:
			inp[0] -= 1
			inp[1] -= 1
		if len(inp) == 2:
			(a, b) = inp
			g[a].append(b)
			if not Directed:
				g[b].append(a)
		elif len(inp) == 3:
			(a, b, c) = inp
			aa = (inp[0], inp[2])
			bb = (inp[1], inp[2])
			g[a].append(bb)
			if not Directed:
				g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}):
	mp = [1] * (w + 2)
	found = {}
	for i in range(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [1] + [mp_def[j] for j in s] + [1]
	mp += [1] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def bit_combination(k, n=2):
	rt = []
	for tb in range(n ** k):
		s = [tb // n ** bt % n for bt in range(k)]
		rt += [s]
	return rt

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['YES', 'NO']
Yn = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
l_alp = string.ascii_lowercase
input = lambda : sys.stdin.readline().rstrip()

def ran_input():
	import random
	n = random.randint(4, 16)
	(rmin, rmax) = (1, 10)
	a = [random.randint(rmin, rmax) for _ in range(n)]
	return (n, a)
show_flg = False
show_flg = True
t = I()
for _ in range(t):
	(n, m) = LI()
	a = LI()
	ans = min(m, sum(a))
	print(ans)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = m
	rem = a[0] - m
	if rem < 0:
		rem = rem * -1
	if rem <= sum(a[1:]):
		ans = m
	elif rem > sum(a[1:]):
		ans = sum(a)
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	array = list(map(int, input().split()))
	sm = sum(array)
	print(min(sm, m))


z = int(input(''))
y = 0
while y < z:
	y = y + 1
	num = input().split(' ')
	a = input().split(' ')
	x = 1
	e = int(num[1])
	f = int(a[0])
	diff = int(num[1]) - int(a[0])
	t = 0
	while x < int(num[0]):
		m = int(a[x])
		t = t + m
		x += 1
	if t >= diff:
		f = f + diff
		print(f)
	else:
		f = f + t
		print(f)


t = int(input())
for times in range(0, t):
	(n, m) = list(map(int, input().split(' ')))
	students = list(map(int, input().split(' ')))
	needed_score = m - students[0]
	others_scores = 0
	for i in range(1, len(students)):
		others_scores = others_scores + students[i]
	if others_scores >= needed_score:
		print(m)
	else:
		print(students[0] + others_scores)


nTest = int(input())
while nTest > 0:
	l_input = list(map(int, input().split()))
	n = l_input[0]
	m = l_input[1]
	s = 0
	a = list(map(int, input().split()))
	s = sum(a)
	if s > m:
		s = m
	print(s)
	nTest = nTest - 1


t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	scores = [int(s) for s in input().split()]
	sumScores = sum(scores)
	if sumScores > m:
		print(m)
	else:
		print(sumScores)
	t -= 1


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		(N, M) = [int(x) for x in input().split()]
		A = [int(x) for x in input().split()]
		ans = min(sum(A), M)
		print(ans)
main()


for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	a[0] = m
	while m > s:
		m -= 1
	print(m)


t = int(input())
for _ in range(0, t):
	(__, m) = map(int, input().split())
	arr = map(int, input().split())
	print(min(sum(arr), m))


n = int(input())
listA = []
listB = []
for i in range(0, n):
	sum = 0
	(t, h) = [int(i) for i in input().split()]
	r = list(map(int, input().split()))
	r.sort()
	for k in range(0, t):
		sum = sum + r[k]
	if sum < h:
		listA.append(sum)
	else:
		listA.append(h)
for i in range(0, n):
	print(listA[i])


k = int(input())
for i in range(k):
	(n, m) = [int(j) for j in input().split()]
	sm = sum(map(int, input().split()))
	print(min(m, sm))


x = int(input())
lst = []
for i in range(0, x):
	(n, m) = map(int, input().split())
	x = list(map(int, input().split()))
	c = sum(x) if m - sum(x) > 0 else m
	lst.append(c)
print(*lst, sep='\n')


for i in range(int(input())):
	(n, m) = map(int, input().split())
	li = list(map(int, input().split()))
	a = sum(li)
	if a >= m:
		print(m)
	else:
		print(a)


k = []
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	k.append(min(m, sum(a)))
for i in k:
	print(i)


t = int(input())
for T in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	print(min(sum(a), m))


t = int(input())
for tt in range(t):
	(n, m) = map(int, input().split())
	li = list(map(int, input().split()))
	x = sum(li)
	x = min(x, m)
	print(x)


from math import ceil, sqrt, gcd, log, floor
from collections import deque

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def li():
	return list(mi())

def msi():
	return map(str, input().strip().split(' '))

def lsi():
	return list(msi())
for _ in range(ii()):
	(n, m) = mi()
	a = li()
	s = a[0] + sum(a[1:])
	print(min(s, m))


a = int(input())
for x in range(a):
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	if b[0] > 1:
		if b[1] - c[0] <= sum(c) - c[0]:
			print(b[1])
		else:
			print(sum(c))
	else:
		print(c[0])


for case in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	scores = [int(x) for x in input().split()]
	if n == 1:
		print(scores[0])
	else:
		current = scores[0]
		rest = scores[1:]
		rest_sum = sum(rest)
		print(min(m, current + rest_sum))


from sys import stdin
for _ in range(int(input())):
	(n, k) = map(int, stdin.readline().rstrip().split(' '))
	l = list(map(int, stdin.readline().rstrip().split(' ')))
	z = sum(l)
	print(min(z, k))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def main():
	t = I()
	rr = []
	for _ in range(t):
		(n, m) = LI()
		a = LI()
		rr.append(min(sum(a), m))
	return JA(rr, '\n')
print(main())


def main():
	t = int(input())
	while t:
		(a, b) = map(int, input().split())
		array = list(map(int, input().split()))
		average = sum(array) / len(array)
		if average * len(array) - b >= 0:
			print(b)
		elif average * len(array) - b < 0:
			print(int(b + average * len(array) - b))
		t -= 1
main()


x = int(input())
op = []
for i in range(x):
	st = list(map(int, input().split()))
	mark = list(map(int, input().split()))
	s = sum(mark)
	if s > st[1]:
		op.append(st[1])
	else:
		op.append(s)
for i in op:
	print(i)


t = int(input())
a = []
for j in range(t):
	(n, m) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	sum = 0
	for i in arr:
		sum += i
	if sum >= m:
		a.append(m)
	elif sum < m:
		a.append(sum)
print(*a, sep='\n')


for _ in range(int(input())):
	X = list(map(int, input().split()))
	Students = list(map(int, input().split()))
	print(min(X[1], sum(Students)))


t_count = int(input().strip())
while t_count != 0:
	(n, m) = list(map(int, input().strip().split(' ')))
	ai_val = list(map(int, input().strip().split(' ')))
	sum_0 = 0
	for i in ai_val:
		if sum_0 > m:
			break
		sum_0 += i
	print(min(sum_0, m))
	t_count -= 1


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ar = list(map(int, input().split()))
	(a1, tmp) = (m / n, 0)
	for i in ar:
		tmp += i
	t = tmp / n
	if a1 <= t:
		print(m)
	else:
		print(tmp)


for i in range(int(input())):
	b = 0
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	for u in range(n):
		b = b + a[u]
	if b < m:
		print(b)
	else:
		print(m)


for i in range(int(input())):
	(n, m) = list(map(int, input().strip().split()))
	t = list(map(int, input().strip().split()))
	s = sum(t)
	if s >= m:
		print(m)
	else:
		print(s)


a = int(input())
for i in range(0, a):
	max = 0
	b = input().split()
	c = list(map(int, b))
	d = input().split()
	e = list(map(int, d))
	for i in range(0, c[0]):
		if max + e[i] < c[1]:
			max = max + e[i]
		else:
			max = c[1]
			break
	print(max)


cases = int(input())
for case in range(cases):
	(n, m) = [int(i) for i in input().split()]
	s = [int(i) for i in input().split()]
	total = sum(s)
	myscore = min(m, total)
	print(myscore)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	d = 0
	l = list(map(int, input().split()))
	if sum(l[0:]) <= m:
		print(sum(l))
	else:
		d = abs(sum(l) - m)
		print(sum(l) - d)


import math
from collections import *
import sys
from functools import reduce

def get_ints():
	return map(int, input().strip().split())

def get_list():
	return list(get_ints())

def get_string():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
DIRECTIONS = [[0, 1], [0, -1], [1, 0], [1, -1]]
NEIGHBOURS = [(i, j) for i in range(-1, 2) for j in range(-1, 2) if i != 0 or j != 0]
OrdUnicode_a = ord('a')
OrdUnicode_A = ord('A')
CAPS_ALPHABETS = {chr(i + OrdUnicode_A): i for i in range(26)}
SMOL_ALPHABETS = {chr(i + OrdUnicode_a): i for i in range(26)}
UGLYMOD = int(1000000000.0) + 7
SEXYMOD = 998244353
MAXN = int(100000.0) + 1
for _testcases_ in range(int(input())):
	(n, k) = get_ints()
	li = get_list()
	print(min(k, sum(li)))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	sum2 = sum(map(int, input().split()))
	if sum2 < b:
		print(sum2)
	else:
		print(b)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	end = len(c) - 1
	while True:
		if c[0] + c[end] < b and end != 0:
			c[0] = c[0] + c[end]
			end = end - 1
		elif c[0] + c[end] == b and end != 0:
			c[0] = c[0] + c[end]
			break
		elif c[0] + c[end] > b and end != 0:
			if b - c[0] <= c[end]:
				c[0] = c[0] + (b - c[0])
				break
			else:
				break
		else:
			break
	print(c[0])


for i in range(int(input())):
	(n, m) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	if sum(arr) >= m:
		print(m)
	else:
		print(sum(arr))


for i in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	c = sum(a)
	d = len(a)
	while c < k:
		k -= 1
	print(k)


t = int(input())
for i in range(0, t):
	(no, hm) = map(int, input().split())
	a = list(map(int, input().split()))
	asum = sum(a)
	if asum >= hm:
		omax = hm
	else:
		omax = asum
	print(omax)


for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	w = [int(i) for i in input().split()]
	print(m if m <= sum(w) else sum(w))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	s = s - a[0]
	if s >= m - a[0]:
		print(m)
	else:
		print(s + a[0])


def maximizescore(x, y):
	return min(sum(x), y)
cases = int(input())
for _ in range(cases):
	(l, y) = list(map(int, input().split()))
	x = list(map(int, input().split()))
	print(maximizescore(x, y))


import bisect
from queue import Queue
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	needed = m - arr[0]
	if needed == 0:
		print(arr[0])
		continue
	for i in range(1, n):
		if needed == 0:
			break
		elif arr[i] < needed:
			arr[0] += arr[i]
			needed -= arr[i]
			arr[i] = 0
		else:
			arr[0] += needed
			arr[i] -= needed
			needed = 0
	print(arr[0])


t = int(input())
for j in range(t):
	(n, m) = map(int, input().split(' '))
	list1 = list(map(int, input().split(' ')))
	sum1 = sum(list1[1:])
	if sum1 - list1[0] >= m:
		print(m)
	elif sum1 + list1[0] >= m:
		print(m)
	else:
		print(sum1 + list1[0])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	if sum(arr) == m or sum(arr) > m:
		print(m)
	else:
		print(sum(arr))


n = input
for i in range(int(n())):
	x = list(map(int, n().split()))
	y = list(map(int, n().split()))
	z = sum(y)
	if z <= x[1]:
		print(z)
	elif z >= x[1]:
		print(x[1])


t = int(input())
for i in range(t):
	a = list(map(int, input().split(' ')))
	cal = list(map(int, input().split(' ')))
	sum = 0
	for i in cal:
		sum += i
	if sum >= a[1]:
		print(a[1])
	else:
		print(sum)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		(n, m) = list(map(int, input().split()))
		scores = list(map(int, input().split()))
		sumscore = sum(scores)
		if sumscore >= m:
			yield m
		else:
			yield sumscore
t = int(input())
ans = gift()
print(*ans, sep='\n')


t = int(input())
end_result = ''
for _t in range(t):
	(n, m) = map(int, input().split())
	s = sum(list(map(int, input().split())))
	result = str(m)
	if m > s:
		result = str(s)
	end_result += result + '\n'
print(end_result)


for t in range(int(input())):
	(n, m) = [int(j) for j in input().split()]
	l = [int(j) for j in input().split()]
	print(min(sum(l), m))


t = int(input())
for qewq in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = a[1:]
	f = sum(b)
	print(min(a[0] + f, m))


for _ in range(int(input())):
	(N, M) = map(int, input().split())
	L = map(int, input().split())
	lim = min(M, sum(L))
	print(lim)


for _ in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	avg = sum(a) / n
	print(min(sum(a), m))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	if n > 1:
		s = sum(arr[1:])
		for i in range(m, arr[0] - 1, -1):
			x = i - arr[0]
			if s >= x:
				print(i)
				break
	else:
		print(arr[0])


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	su = sum(l)
	print(min(su, m))


t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	l = list(map(int, input().split()))
	m = sum(l)
	if m >= y:
		print(y)
	else:
		print(sum(l))


from math import factorial
from collections import Counter
from heapq import heapify, heappop, heappush
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')
import bisect

def main():
	for _ in range(N()):
		(n, m) = RL()
		arr = list(RL())
		sm = sum(arr)
		if sm < m:
			print(sm)
		else:
			print(m)
main()


test = int(input())
for i in range(test):
	sum = 0
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	for j in range(n):
		sum += a[j]
	if n == 1:
		print(a[0])
	elif sum == 0:
		print(0)
	elif sum < m:
		print(sum)
	else:
		print(m)


for _ in range(int(input())):
	(k, l) = map(int, input().split())
	m = list(map(int, input().split()))
	if sum(m[1:]) >= l - m[0]:
		print(l)
	else:
		print(sum(m))


n = int(input())
d = []
for j in range(n):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	s = 0
	for i in range(len(c)):
		s = s + c[i]
	if s < b:
		d.append(s)
	else:
		d.append(b)
for i in range(len(d)):
	print(d[i])


a = int(input())
for i in range(a):
	b = input().split()
	c = input().split()
	m = int(b[1])
	n = int(b[0])
	for j in range(n):
		c[j] = int(c[j])
	for k in range(1, n):
		while c[0] < m and c[k] > 0:
			c[k] -= 1
			c[0] += 1
	print(c[0])


import sys, math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
t = 1
t = inp()
for tt in range(t):
	(n, m) = invr()
	a = inlt()
	print(min(sum(a), m))


import sys
from collections import defaultdict

def solve(N, M, A):
	total = sum(A)
	return min(total, M)
input = sys.stdin.readline
T = int(input())
for t in range(T):
	(N, M) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	ans = solve(N, M, A)
	print(ans)


n_tests = int(input())
for i in range(n_tests):
	(students, nota_max) = [int(i) for i in input().split()]
	notas = [int(i) for i in input().split()]
	soma = 0
	for j in notas:
		soma = soma + j
		if soma >= nota_max:
			break
	if soma >= nota_max:
		print(nota_max)
	else:
		print(soma)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	if sum(l) <= m:
		print(sum(l))
	else:
		print(m)


for _ in range(int(input())):
	(students, highest_mark) = map(int, input().split())
	student_marks = list(map(int, input().split()))
	my_mark = 0
	for i in student_marks:
		my_mark = my_mark + i
	if my_mark > highest_mark:
		print(highest_mark)
	else:
		print(my_mark)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	x = list(map(int, input().split()))
	print(min(m, sum(x)))


def main():
	t = int(input())
	for i in range(t):
		(n, m) = map(int, input().split())
		scores = list(map(int, input().split()))
		print(min(scores[0] + sum(scores[1:]), m))
main()


t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = 0
	for i in range(1, len(arr)):
		s += arr[i]
	ans = arr[0]
	ans = min(s + ans, m)
	print(ans)
	t -= 1


from math import *
zzz = int(input())
for zz in range(zzz):
	(n, m) = list(map(int, input().split()))
	a = [int(i) for i in input().split()]
	print(int(min(sum(a), m)))


from math import *

def binarySearch(arr, x, i):
	l = i
	r = len(arr) - 1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def js(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] <= x:
			ans = m
			l = m + 1
		else:
			r = m - 1
	return ans

def jg(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] >= x:
			ans = m
			r = m - 1
		else:
			l = m + 1
	return ans
for __ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	if n == 1:
		print(l[0])
	else:
		ss = sum(l[1:])
		if ss + l[0] > m:
			print(m)
		else:
			print(ss + l[0])


for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	ind = 1
	m = max(0, m - a[0])
	while ind < n:
		if m - a[ind] < 0:
			a[0] += m
			break
		else:
			a[0] += a[ind]
			m -= a[ind]
		ind += 1
	print(a[0])


def media(n, maximo, s):
	diff = maximo - s[0]
	nota = maximo
	for i in range(1, n):
		diff -= s[i]
	if diff > 0:
		nota -= diff
	print(nota)
l = int(input())
for i in range(l):
	np1 = list(map(int, input().split()))
	n = np1[0]
	maximo = np1[1]
	np = list(map(int, input().split()))
	media(n, maximo, np)


test = int(input())
for ij in range(test):
	id = list(map(int, input().split()))
	n = id[0]
	m = id[1]
	a = list(map(int, input().split()))
	for i in range(1, n):
		a[0] += a[i]
	print(min(a[0], m))


t = int(input())
answer = []
for i in range(t):
	l = list(input().split())
	n = int(l[0])
	m = int(l[1])
	q = list(input().split())
	a = [int(i) for i in q]
	if sum(a) >= m:
		answer.append(m)
	else:
		answer.append(sum(a))
for i in answer:
	print(i)


t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	s = l[0]
	s1 = 0
	for i in range(1, len(l)):
		s1 += l[i]
	print(min(s + s1, m))


for m in range(int(input())):
	nm = list(map(int, input().split()))
	a = list(map(int, input().split()))
	summa = 0
	for i in range(1, nm[0]):
		summa += a[i]
	if summa + a[0] >= nm[1]:
		print(nm[1])
	else:
		print(summa + a[0])


t = int(input())
a = []
for i in range(t):
	(n, m) = map(int, input().split())
	b = list(map(int, input().split()))
	a.append([b, m])
for i in a:
	k = i[0]
	q = i[1]
	p = sum(k) - k[0]
	if p + k[0] > q:
		print(q)
	else:
		print(p + k[0])


import sys
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
import math

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def main():
	t = inin()
	for _ in range(t):
		(n, m) = cin()
		a = ain()
		y = sum(a)
		y = min(y, m)
		print(y)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


a = int(input())
for i in range(0, a):
	(x, m) = list(map(int, input().split()))
	b = input()
	l = list(map(int, b.split()))
	s = sum(l)
	c = min(m, s)
	print(c)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(j) for j in input().split()]
	print(min(sum(a), k))


for i in range(int(input())):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	if sum(c) > b:
		print(b)
	else:
		print(sum(c))


t = int(input())
for i in range(t):
	(n, m) = (int(z) for z in input().split())
	l = list(map(int, input().split()))
	total = sum(l)
	if m <= total:
		print(m)
	else:
		print(total)


for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	l = [int(i) for i in input().split()]
	soma = sum(l)
	media = soma / n
	sobra = 0
	for i in range(1, n):
		sobra += l[i]
	print(min(sobra + l[0], m))


for i in range(int(input())):
	(n, m) = map(int, input().split())
	list1 = list(map(int, input().split()))
	sumofmarks = sum(list1)
	if sumofmarks <= m:
		print(sumofmarks)
	else:
		print(m)


def one():
	return int(input())

def more():
	return map(int, input().split())
for _ in range(one()):
	(n, m) = more()
	l = list(more())
	sum = 0
	for i in range(1, n):
		sum += l[i]
	print(min(m, l[0] + sum))


k = int(input())
for l in range(k):
	(n, m) = [int(x) for x in input().split(' ')]
	db = [int(x) for x in input().split(' ')]
	print(min([sum(db), m]))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	lis = list(map(int, input().split()))
	if sum(lis) < b:
		print(sum(lis))
	else:
		print(b)


T = int(input())
for tick in range(0, T):
	[n, m] = input().split()
	n = int(n)
	m = int(m)
	d = input().split()
	limit = int(d[0])
	for i in range(1, n):
		limit += int(d[i])
	print(m if limit > m else limit)


t = int(input())
for i in range(0, t):
	(N, K) = map(int, input().split())
	K = int(K)
	l = list(map(int, input().split()))
	sum = 0
	for j in range(0, len(l)):
		sum += l[j]
	print(min(sum, K))


T = int(input(''))
list2 = []
for i in range(T):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	list1 = list(map(int, input().split()))
	list1.sort()
	a = list1.pop(0)
	for j in range(len(list1)):
		if a + list1[j] > m:
			a = m
			break
		else:
			a = a + list1[j]
	list2.append(a)
for i in list2:
	print(i)


T = int(input())
for i in range(T):
	(n, m) = map(int, input().split())
	ai = list(map(int, input().split()))
	print(min(ai[0] + sum(ai[1:]), m))


t = int(input())
out = []
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	a1 = sum(a)
	if a1 <= m:
		out.append(a1)
	else:
		out.append(m)
for i in out:
	print(i)


for _ in range(int(input())):
	(n, m) = map(int, input().strip().split())
	r = list(map(int, input().strip().split()))[:n]
	if sum(r) > m:
		print(m)
	else:
		print(sum(r))


t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	a = [int(s) for s in input().split()]
	if n == 1:
		print(a[0])
	else:
		print(min(m, sum(a)))
	t -= 1


for _ in range(int(input())):
	li = list(map(int, input().split()))
	n = li[0]
	m = li[1]
	g = list(map(int, input().split()))
	s = sum(g)
	print(min(s, m))


def solve():
	(n, m) = [int(s) for s in input().strip().split()]
	A = [int(s) for s in input().strip().split()]
	result = min(sum(A), m)
	print(result)

def main():
	for _ in range(int(input().strip())):
		solve()
main()


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	(s, a) = (input().split(), 0)
	for i in range(n):
		a = a + int(s[i])
	print(min(m, a))


for x in range(int(input())):
	(h, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	if m < sum(a):
		print(m)
	else:
		print(sum(a))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	sa = sum(a[1:])
	res = m - a[0]
	if res <= sa:
		print(m)
	else:
		print(a[0] + sa)


t = int(input())
while t != 0:
	(n, m) = map(int, input().split())
	arr = map(int, input().split())
	print(min(m, sum(arr)))
	t -= 1


test_cases = []
score_list = []
case_id = 0
t = int(input())
for i in range(1, t + 1):
	test_case = input()
	test_case = [int(x) for x in test_case.split(' ')]
	test_cases.append(test_case)
	test_scores = input()
	test_scores = [int(x) for x in test_scores.split(' ')]
	score_list.append(test_scores)
for case in test_cases:
	sum_of_all_but_first = 0
	case_id += 1
	n = case[0]
	m = case[1]
	max = score_list[case_id - 1][0]
	for k in score_list[case_id - 1]:
		sum_of_all_but_first += k
	sum_of_all_but_first -= max
	for d in range(sum_of_all_but_first):
		if max < m:
			max += 1
		else:
			break
	print(max)


t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	ar = list(map(int, input().split()))
	s = sum(ar)
	if m < s:
		print(m)
	else:
		print(s)
	t -= 1


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	uch = list(map(int, input().split()))
	me = uch[0]
	if n != 1:
		oth = sum(uch[1:])
		print(min(m, me + oth))
	else:
		print(me)


tc = int(input())
for i in range(tc):
	(m, n) = map(int, input().split())
	sum = 0
	mew = input()
	mew = mew.split()
	for i in mew:
		i = int(i)
		sum += i
	print(min(sum, n))


t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	my = a[0]
	tot = sum(a)
	ans = min(m, tot - my + my)
	print(ans)


t = int(input())
for r in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	summ = sum(l)
	ans = min(summ, m)
	print(ans)


a = int(input())
for i in range(a):
	(n, m) = map(int, input().split())
	z = list(map(int, input().split()))
	t = sum(z)
	q = m - z[0]
	r = min(q, sum(z[1:]))
	print(r + z[0])


t = int(input())
for i in range(t):
	(n, m) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	print(min(a[0] + sum(a[1:]), m))


t = int(input())
while t:
	q = list(map(int, input().split()))
	(n, m) = q
	s = list(map(int, input().split()))
	s = sum(s)
	if s >= m:
		print(m)
	else:
		print(s)
	t -= 1


for T in range(int(input())):
	(stu_num, max_sco) = map(int, input().split())
	scores = list(map(int, input().split()))
	if max_sco <= sum(scores):
		print(max_sco)
	else:
		print(sum(scores))


def rr():
	return input().rstrip()

def rri():
	return int(rr())

def rrl():
	return list(map(int, rr().split()))

def rrt():
	return tuple(map(int, rr().split()))
from collections import defaultdict

def mus(d=0):
	return defaultdict(defaultdict(d))

def ms(x, y, d=0):
	return [[0] * y for i in range(x)]

def ar(x, d=0):
	return [d] * x

def ppm(m, n=0, x=0, y=0):
	print('\n'.join(('\t'.join((str(m[j][i]) for j in range(y or n))) for i in range(x or n))))

def ppa(a, n):
	print('\t'.join(map(str, a[0:n])))
import math

def read():
	(n, m) = rrl()
	st = rrl()
	return (n, m, st)

def solve(n, m, st):
	ans = min(sum(st), m)
	return ans
test_count = rri()
for _ in range(test_count):
	input_data = read()
	result = solve(*input_data)
	print(result)


y = int(input())
for i in range(y):
	(x, g) = map(int, input().split())
	l = list(map(int, input().split()))
	if sum(l) >= g:
		print(g)
	elif sum(l) < g:
		print(sum(l))


for _ in range(int(input())):
	(number, tot) = [int(number) for number in input().split()]
	li = list(map(int, input().split()))
	s = sum(li)
	if tot <= s:
		print(tot)
	else:
		print(s)


t = int(input())
while t > 0:
	a = []
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	x = sum(a) / n
	if m <= sum(a):
		print(m)
	elif m > sum(a):
		print(sum(a))
	t = t - 1


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	lis = list(map(int, input().split()))
	s = 0
	for i in range(len(lis)):
		s = s + lis[i]
	if s > k:
		print(k)
	else:
		print(s)


import sys

def input():
	return sys.stdin.readline().rstrip()
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	s = sum(arr)
	print(min(s, m))


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	for i in range(t):
		(n, m) = map(int, input().split())
		a = list(map(int, input().split()))
		s = sum(a)
		if s <= m:
			print(s)
		else:
			print(m)
main()


t = int(input())
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	sumScore = sum(A)
	if m < sumScore:
		print(m)
	else:
		print(sumScore)


t = int(input())
A = []
for i in range(t):
	[n, m] = [int(x) for x in input().split()]
	L = [int(x) for x in input().split()]
	A.append(sum(L) if sum(L) < m else m)
for i in A:
	print(i)


t = int(input())
for _ in range(t):
	nm = input().split()
	n = int(nm[0])
	m = int(nm[1])
	ar = input().split()
	ar = [int(y) for y in ar]
	if sum(ar) >= m:
		print(m)
	else:
		print(sum(ar))


for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	diff = m - a[0]
	print(min(a[0] + diff, s))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [int(i) for i in input().split()]
	sum2 = sum(a) - a[0]
	if sum2 >= m - a[0]:
		print(m)
	else:
		print(a[0] + sum2)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	ans = min(m, sum(A))
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	ss = sum(a)
	if m <= ss:
		print(m)
	else:
		print(ss)


t = int(input())
for i in range(t):
	scores = list(map(int, input().strip().split()))
	students = int(scores[0])
	highest = int(scores[1])
	scores = list(map(int, input().strip().split()))
	sums = sum(scores)
	if sums < highest:
		print(sums)
	else:
		print(highest)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	L = list(map(int, input().split()))
	s = 0
	for j in range(len(L)):
		s += L[j]
	if s > m:
		print(m)
	else:
		print(s)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	i = 1
	while arr[0] < m and i < n:
		left = m - arr[0]
		if arr[i] - left >= 0:
			arr[0] = m
			arr[i] -= left
			break
		else:
			arr[0] += arr[i]
			arr[i] = 0
		i += 1
	print(arr[0])


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) >= m:
		print(m)
	else:
		print(sum(a))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = [int(item) for item in input().split()]
	if n == 1:
		print(a[0])
		continue
	total = sum(a)
	print(min(total, m))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l[1:])
	if l[0] + s <= m:
		print(s + l[0])
	else:
		print(m)


t = int(input().strip())
for _ in range(t):
	(n, m) = map(int, input().strip().split())
	nums = [int(i) for i in input().strip().split()]
	result = sum(nums)
	if result >= m:
		print(m)
	else:
		print(result)


def grades(arr, m):
	if len(arr) == 1:
		return arr[0]
	diff = m - arr[0]
	if diff <= sum(arr[1:]):
		return m
	else:
		return arr[0] + sum(arr[1:])
t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().rstrip().split()))
	arr = list(map(int, input().rstrip().split()))
	print(grades(arr, m))


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	(n, m) = stdin.readline().strip().split(' ')
	(n, m) = (int(n), int(m))
	arr = list(map(int, stdin.readline().strip().split(' ')))
	total = sum(arr)
	my_score = arr[0]
	other = total - my_score
	stdout.write(str(min(m, total)) + '\n')


for i in range(int(input())):
	(n, m) = map(int, input().split())
	x = [int(q) for q in input().split()]
	if m <= sum(x):
		print(m)
	else:
		print(sum(x))


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
li = lambda : list(map(int, input().split()))

def case():
	(n, m) = li()
	a = li()
	s = sum(a)
	print(min(s, m))
for _ in range(int(input())):
	case()


import sys
import math
import itertools
t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	summ = 0
	for num in a:
		summ += num
	print(min(summ, m))
	t -= 1


def solve(l):
	for i in range(l):
		s = 0
		(a, m) = map(int, input().split())
		v = input().split()
		for i in range(1, int(a)):
			s += int(v[i])
		if s + int(v[0]) >= m:
			print(m)
		else:
			print(int(v[0]) + s)
solve(int(input()))


def main():
	t = int(input())
	for _ in range(t):
		(n, m) = map(int, input().split())
		a = list(map(int, input().split()))
		print(min(m, sum(a)))
main()


t = int(input())
for test in range(t):
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	l = list(map(int, input().split()))
	sm = sum(l)
	print(min(m, sm))


for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	c = list(map(int, input().split()))
	print(min(b, sum(c)))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	avg = sum(l) / n
	x = sum(l[1:])
	print(min(m, l[0] + x))


num_cases = int(input())
for case in range(num_cases):
	line = input().split()
	n = int(line[0])
	m = int(line[1])
	grades = input().split()
	adds = 0
	for i in range(1, len(grades)):
		adds += int(grades[i])
	print(min(m, int(grades[0]) + adds))


t = int(input())
for ii in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	if s >= m:
		print(m)
	else:
		print(s)


t = int(input())
r = []
q = 1
for i in range(t):
	(n, m) = map(int, input().split())
	s = input()
	arr = s.split()
	arr = [int(i) for i in arr]
	r = arr.copy()
	a = sum(arr) / n
	arr[0] = m
	if sum(arr) - sum(r) <= sum(r[1:]):
		print(arr[0])
	else:
		b = sum(arr) - (sum(arr) - sum(r))
		print(b)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	tot = sum(map(int, input().split()))
	print(min(tot, m))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	ar = list(map(int, input().split()))
	if n == 1:
		print(ar[0])
	elif max(ar) == m:
		print(m)
	else:
		s = 0
		j = 0
		ar.sort(reverse=False)
		while m > s and j < len(ar):
			s = s + ar[j]
			j += 1
		if j == len(ar):
			if m >= s:
				print(s)
			else:
				print(m)
		else:
			print(m)


from collections import defaultdict
import math
from functools import reduce
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(min(m, sum(arr)))


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	s = sum(a)
	ans = min(s, m)
	print(ans)


n = int(input())
for i in range(n):
	nums = []
	grades = []
	avg = 0
	nums = list(map(int, input().split()))
	grades = list(map(int, input().split()))
	for j in range(1, len(grades)):
		if grades[0] < nums[1]:
			grades[0] += grades[j]
			grades[j] = 0
	if grades[0] > nums[1]:
		grades[0] -= grades[0] - nums[1]
		grades[1] += grades[0] - nums[1]
	print(grades[0])


for _ in range(int(input())):
	y = list(map(int, input().split()))
	x = list(map(int, input().split()))
	n = y[0]
	maxi = y[1]
	res = sum(x)
	if res <= maxi:
		print(res)
	else:
		print(maxi)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	sn = sum(a)
	f = m - a[0]
	sn -= a[0]
	ans = min(sn, f) + a[0]
	print(ans)


I = input
for _ in [0] * int(I()):
	(m, n) = map(int, I().split())
	print(min(n, sum(map(int, I().split()))))


from sys import stdin, stdout
import math
import heapq
t = 1

def aint():
	return int(input().strip())

def lint():
	return list(map(int, input().split()))

def fint():
	return list(map(int, stdin.readline().split()))

def main():
	(n, m) = lint()
	l = lint()
	s = sum(l)
	print(min(m, s))
t = aint()
for i in range(t):
	main()


import sys

def input():
	return sys.stdin.readline()[:-1]
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	print(min(sum(a), m))


t = int(input())
for x in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = 0
	for x in a:
		b += x
	if b == m or b < m:
		print(b)
	else:
		print(m)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	L = list(map(int, input().split()))
	if sum(L) >= m:
		print(m)
	else:
		print(sum(L))


t = int(input())
for x in range(t):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	score = list(map(int, input().split()))
	total = sum(score)
	diff = m - score[0]
	rest = total - score[0]
	if diff >= rest:
		print(score[0] + rest)
	else:
		print(m)


t = int(input())
while t > 0:
	(n, high) = [int(n) for n in input().split()]
	a = list(map(int, input().strip().split()))[:n]
	final_s = sum(a)
	if high <= final_s:
		print(high)
	else:
		print(final_s)
	t = t - 1


I = lambda : map(int, input().split())
for _ in range(int(input())):
	(_, m) = I()
	print(min(m, sum(I())))


for tc in range(int(input())):
	(k1, k2) = map(int, input().split())
	l1 = [int(i) for i in input().split()]
	s = 0
	for i in l1:
		s += i
	print(min(k2, s))


a = int(input())
for _ in range(a):
	(b, c) = map(int, input().split())
	d = [int(i) for i in input().split()]
	print(min(sum(d), c))


test = int(input())
while test:
	n = input().split(' ')
	lis = input().split(' ')
	sum1 = 0
	for i in lis:
		sum1 = sum1 + int(i)
	print(min(sum1, int(n[1])))
	test = test - 1


for _ in [0] * int(input()):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	c = sum(a)
	if c > m:
		print(m)
	else:
		print(c)


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	p = list(map(int, input().split()))
	sum1 = 0
	for i in range(0, n):
		sum1 = sum1 + p[i]
	if sum1 >= d:
		print(d)
	else:
		print(sum1)


def main():
	t = int(input())
	for _ in range(t):
		change()

def change():
	(n, m) = list(map(int, input().split(' ')))
	a = list(map(int, input().split(' ')))
	if sum(a) >= m:
		print(m)
	else:
		print(sum(a))
main()


cases = int(input())
for _ in range(cases):
	(a, m) = map(int, input().split())
	c = list(map(int, input().split()))
	d = sum(c)
	e = d / a
	if d >= m:
		print(m)
	else:
		print(d)


import math
testCases = int(input())
for _ in range(testCases):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	diffrence = m - a[0]
	access = sum(a[1:])
	if access >= diffrence:
		print(m)
	else:
		print(a[0] + access)


t = int(input())
for _ in range(t):
	(n, m) = [int(s) for s in input().split()]
	a = [int(s) for s in input().split()]
	cnt = sum((v for v in a))
	if cnt < m:
		print(cnt)
	else:
		print(m)


t = int(input())
for x in range(t):
	(n, m) = map(int, input().split())
	li = [int(x) for x in input().split()]
	s = sum(li)
	if s > m:
		print(m)
	else:
		print(s)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(1, n):
		if a[0] == m:
			break
		p = a[0]
		a[0] += min(m - a[0], a[i])
		a[i] -= a[0] - p
	print(a[0])


import sys

def rint():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().rstrip('\n')

def oint():
	return int(input())
t = oint()
for _ in range(t):
	(n, m) = rint()
	a = list(rint())
	ans = min(sum(a), m)
	print(ans)


t = int(input())
result = list()
for item in range(t):
	input_nm = input().split()
	nm = [int(item) for item in input_nm]
	input_scores = input().split()
	scores = [int(item) for item in input_scores]
	if sum(scores) >= nm[1]:
		result.append(nm[1])
	else:
		result.append(sum(scores))
for i in result:
	print(i)


t = int(input())
while t:
	t = t - 1
	(n, m) = [int(x) for x in input().split()]
	a_i = [int(x) for x in input().split()]
	if sum(a_i) > m:
		print(m)
	else:
		print(sum(a_i))


t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().split()))
	nums = list(map(int, input().split()))
	s = sum(nums)
	print(min(s, m))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	nums = list(map(int, input().split()))
	mx = 0
	cnt = 0
	while cnt <= len(nums) - 1:
		if mx <= m:
			mx += nums[cnt]
			cnt += 1
		else:
			cnt += 1
	if mx > m:
		mx = m
	print(mx)


t = int(input())
for x in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	k = sum(a)
	if k <= m:
		print(k)
	else:
		print(m)


import math

def solve():
	(n, k) = list(map(int, input().split()))
	arr = [int(i) for i in input().split()]
	sum = 0
	for i in arr:
		if sum + i <= k:
			sum += i
		else:
			return k
	return sum
for i in range(int(input())):
	print(solve())


import math, collections, sys
input = sys.stdin.readline

def solve():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	i = 1
	while a[0] < m and i < n:
		if a[i] < m - a[0]:
			a[0] += a[i]
			a[i] = 0
		else:
			a[0] += m - a[0]
			a[i] -= m - a[0]
		i += 1
	print(a[0])
for _ in range(int(input())):
	solve()


MOD = 1000000007
MOD2 = 998244353
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
let = '@abcdefghijklmnopqrstuvwxyz'
for _ in range(ii()):
	(n, m) = f()
	l = il()
	print(min(m, sum(l)))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	d = sum(c)
	if d < b:
		print(d)
	else:
		print(b)


t = int(input())
for i in range(t):
	(n, m) = str(input()).split(' ')
	grades = str(input()).split(' ')
	grades = [int(grade) for grade in grades]
	sumOfGrades = sum(grades)
	if sumOfGrades > int(m):
		print(m)
	else:
		print(sumOfGrades)


x = int(input())
meta = []
grades = []
for c in range(x):
	meta.append(list(map(int, input().split())))
	grades.append(list(map(int, input().split())))
for c in range(x):
	if meta[c][0] == 1:
		print(grades[c][0])
	elif sum(grades[c]) < meta[c][1]:
		print(sum(grades[c]))
	else:
		print(meta[c][1])


for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	lst = [int(i) for i in input().split()]
	sum1 = sum(lst)
	if sum1 >= m:
		print(m)
	else:
		print(sum1)


n = int(input())
temp = []
for i in range(n):
	(std, high) = map(int, input().split())
	temp = input().split()
	summ = 0
	for number in temp:
		summ = summ + int(number)
	if summ >= high:
		print(high)
	else:
		print(summ)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	k = sum(a) / n
	for i in range(m, -1, -1):
		if i / n <= k:
			print(max(i, a[0]))
			break


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	c = l[0]
	for i in range(1, n):
		c += l[i]
		if c >= m:
			c = m
			break
	print(c)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
for _ in range(ii()):
	(n, m) = mi()
	a = li()
	print(min(m, sum(a)))


import sys
from math import ceil
from collections import deque
for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	print(min(m, sum(a)))


def gradealloc(m, ar):
	x = sum(ar)
	if m > x:
		return x
	else:
		return m
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	ar = list(map(int, input().split()))
	print(gradealloc(m, ar))


t = int(input())
for w in range(t):
	(n, m) = (int(i) for i in input().split())
	l = [int(i) for i in input().split()]
	print(min(m, sum(l)))


t = int(input())
for i in range(t):
	data = input().split()
	(n, m) = (int(data[0]), int(data[1]))
	scores = [int(x) for x in input().split()]
	suma = sum(scores)
	if suma >= m:
		print(m)
	else:
		print(suma)


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(t,) = I()
while t:
	t -= 1
	(n, m) = I()
	a = I()
	print(min(m, sum(a)))


from statistics import mean
n = int(input())
for i in range(n):
	l = list(map(int, input().strip().split(' ')))
	s = list(map(int, input().strip().split(' ')))
	if sum(s) <= l[1]:
		print(sum(s))
	elif sum(s) > l[1]:
		print(l[1])


n_cases = int(input())
for _ in range(n_cases):
	(n_students, highest) = map(int, input().split())
	grades = list(map(int, input().split()))
	new = sum(grades[1:]) + grades[0]
	print(min(new, highest))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = 0
	for j in range(1, n):
		ans += a[j]
	ans += a[0]
	if ans > m:
		print(m)
	else:
		print(ans)


for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	v = list(map(int, input().split()))
	o = sum(v)
	if o >= b:
		print(b)
	else:
		print(o)


from sys import stdin

def inp():
	return next((ss.rstrip() for ss in stdin))

def itg():
	return int(inp())

def mpint():
	return map(int, inp().split())
for case in range(itg()):
	(n, m) = mpint()
	arr = mpint()
	print(min(m, sum(arr)))


t = int(input())
a = []
b = []
for i in range(t):
	(n, m) = map(int, input().split()[:2])
	a.append(list(map(int, input().split()[:n])))
	b.append(m)

def chk(a, b):
	if sum(a) >= b:
		return b
	return sum(a)
for i in range(t):
	print(chk(a[i], b[i]))


t = int(input())
while t > 0:
	m = int(input().split()[1])
	M = sum([int(i) for i in input().split()])
	print(min(m, M))
	t -= 1


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	av = sum(arr) / len(arr)
	if sum(arr) >= m:
		print(m)
	else:
		print(sum(arr))


x = int(input())
for a in range(x):
	dados = list(map(int, input().split()))
	notas = list(map(int, input().split()))
	for i in range(1, dados[0]):
		if notas[0] >= dados[1]:
			notas[0] = dados[1]
			break
		elif notas[i] > 0:
			notas[0] += notas[i]
			notas[i] = 0
			if notas[0] >= dados[1]:
				notas[0] = dados[1]
				break
	print(notas[0])


import sys
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = 0
	for i in range(0, len(a)):
		s += a[i]
	print(min(s, m))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	print(min(m, sum(a)))


t = int(input())
for i in range(t):
	(n, m) = tuple(map(int, input().split()))
	l = list(map(int, input().split()))
	a = l[0]
	d = m - l[0]
	if d == 0:
		print(m)
	else:
		for j in range(1, n):
			d -= l[j]
			if d <= 0:
				break
		print(m - max(d, 0))


t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	m = int(l[1])
	l = input().split()
	li = [int(i) for i in l]
	x = sum(li)
	if x >= m:
		print(m)
	else:
		print(x)


R = lambda : map(int, input().split())
(t,) = R()
exec(t * 'n,m=R();print(min(m,sum(R())));')


t = int(input())
while t:
	t -= 1
	m = list(map(int, input().split()))
	ar = list(map(int, input().split()))
	print(min(sum(ar), m[1]))


import math
z = input
for i in range(int(z())):
	(a, b) = z().split()
	b = int(b)
	l = list(map(int, z().split()))
	s = sum(l)
	if s >= b:
		print(b)
	else:
		print(s)


T = int(input())
for test in range(T):
	(n, m) = map(int, input().split())
	lst = list(map(int, input().split()))
	s = sum(lst)
	if s >= m:
		print(m)
	else:
		print(s)


T = int(input())
for _ in range(T):
	(N, M) = map(int, input().split())
	A = [int(a) for a in input().split()]
	print(min(M, sum(A)))


def calc(n: int, m: int, scores: list):
	mySum: int = sum(scores)
	if m <= mySum:
		return m
	if mySum < m:
		return mySum

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		scores: list = list(map(int, input().split()))
		print(calc(n, m, scores))
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ls = [int(x) for x in input().split()]
	print(min(sum(ls), m))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = [int(i) for i in input().split()]
	if sum(l) >= m:
		print(m)
	else:
		print(sum(l))


for ctr in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	k = sum(a)
	p = a[0]
	for i in range(m, a[0], -1):
		if i <= m and i <= k:
			p = i
			break
	print(p)


t = int(input())
while t:
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	temp = sum(l)
	print(k) if k < temp else print(temp)
	t -= 1


t = int(input())
while t:
	line = input().split()
	(n, m) = (int(line[0]), int(line[1]))
	a = input().split()
	a = [int(x) for x in a]
	print(min(sum(a), m))
	t -= 1


k = int(input())
for i in range(k):
	j = input()
	(n, m) = j.split(' ')
	a = input()
	a = a.split(' ')
	n = int(n)
	m = int(m)
	a = [int(i) for i in a]
	s = sum(a)
	if s >= m:
		print(m)
	else:
		print(s)


from sys import stdin, stdout
Pi = lambda x: stdout.write(str(x) + '\n')
S = lambda x: x * (x + 1) // 2
R = lambda : stdin.readline()
Ri = lambda x: map(int, x.split())

def main():
	t = int(R())
	for i in range(t):
		(n, m) = Ri(R())
		A = list(Ri(R()))
		s = sum(A)
		Pi(min(m, s))
main()


t = int(input())
f = []
for i in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	if s >= m:
		f.append(m)
	else:
		f.append(s)
for i in f:
	print(i)


def sol():
	(n, m) = map(int, input().split())
	A = [int(item) for item in input().split()]
	p = sum(A)
	print(p if p < m else m)
t = int(input())
for i in range(t):
	sol()


t = int(input())
for a in range(t):
	str_input = input().split()
	total_estudantes = int(str_input[0])
	maior_nota_possivel = int(str_input[1])
	notas = [int(c) for c in input().split()]
	print(min(sum(notas), maior_nota_possivel))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = 0
	for i in range(n):
		s = s + a[i]
	print(min(s, m))


tests = int(input())
for _ in range(tests):
	(n, m) = (int(x) for x in input().split(' '))
	marks = [int(s) for s in input().split(' ')]
	sm = sum(marks)
	if marks[0] == m:
		print(marks[0])
		continue
	elif m <= sm:
		print(m)
		continue
	else:
		print(sm)


tc = int(input())
t = 0
while t < tc:
	t += 1
	i = input().split()
	a = int(i[0])
	m = int(i[1])
	x = input().split()
	j = 0
	sum = 0
	while j < a:
		sum += int(x[j])
		j += 1
	if sum > m:
		sum = m
	print(sum)


import sys
input = sys.stdin.readline

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		a = list(map(int, input().split()))
		ret = 0
		for score in a:
			ret += score
			if ret >= m:
				ret = m
				break
		print(ret)
main()


t = int(input())
for i in range(0, t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	x = l[0]
	sum = 0
	for j in range(1, len(l)):
		sum = sum + l[j]
	if sum + x >= m:
		print(m)
	else:
		print(sum + x)


q = int(input())
for i in range(q):
	(a, b) = [int(tmp) for tmp in input().split()]
	m = list(map(int, input().split()))
	k = sum(m)
	if k > b:
		print(b)
	elif k < b:
		print(k)
	elif k == b:
		print(k)


t = int(input())
while t:
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	print(min(m, sum(l)))
	t = t - 1


import string

def main():
	(n, m) = map(int, input().split())
	lst = list(map(int, input().split()))
	sm = 0
	for i in lst:
		sm += i
	print(min(sm, m))
t = int(input())
for i in range(t):
	main()


t = int(input())
for i in range(t):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	notas = list(map(int, input().split()))
	if int(notas[0]) == m:
		print(m)
	else:
		for i in range(n - 1):
			notas[0] += notas[i + 1]
		if notas[0] >= m:
			print(m)
		else:
			print(notas[0])


t = int(input())
tests = []
for i in range(t):
	(n, m) = input().split()
	grades = list(map(lambda e: int(e), input().split()))
	tests.append({'highest_score': int(m), 'grades': grades})
for i in range(len(tests)):
	students = len(tests[i]['grades'])
	j = 1
	while tests[i]['grades'][0] < tests[i]['highest_score'] and j < students:
		if tests[i]['grades'][j] > 0:
			tests[i]['grades'][j] -= 1
			tests[i]['grades'][0] += 1
		else:
			j += 1
	print(tests[i]['grades'][0])


t = int(input())
for test in range(t):
	(n, m) = [int(x) for x in input().strip().split()]
	l = [int(x) for x in input().strip().split()]
	ans = -1
	s = sum(l)
	if s > m:
		ans = m
	else:
		ans = s
	print(ans)


def main():
	testCase = int(input())
	for test in range(testCase):
		(n, k) = [int(i) for i in input().split()]
		a = [int(i) for i in input().split()]
		ans = min(sum(a), k)
		print(ans)
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(1, n):
		if a[i] > 0 and a[i] + a[0] <= m:
			a[0] += a[i]
			a[i] = 0
		elif a[i] > 0 and m - a[0] < a[i]:
			a[0] += m - a[0]
			a[i] -= m - a[0]
	print(a[0])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	li = list(map(int, input().split()))
	if li[0] == m:
		print(m)
	else:
		for i in li[1:]:
			li[0] = min(li[0] + i, m)
			if li[0] == m:
				break
		print(li[0])


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	if arr[0] == m:
		print(m)
		continue
	if n == 1:
		print(arr[0])
		continue
	j = 1
	flag = 0
	while j < n:
		arr[0] += arr[j]
		if arr[0] >= m:
			flag = 1
			break
		j += 1
	if flag == 1:
		print(m)
	else:
		print(arr[0])


t = int(input())
for test in range(t):
	line1 = list(map(int, input().split()))
	num_students = line1[0]
	max_score = line1[1]
	line2 = list(map(int, input().split()))
	my_score = line2[0]
	total = sum(line2)
	avg = total / num_students
	if max_score >= total:
		print(total)
	else:
		print(max_score)


n = int(input())
for _ in range(n):
	(_, b) = map(int, input().split())
	print(min(b, sum(list(map(int, input().split())))))


t = int(input())
for i in range(t):
	(n, m) = [int(j) for j in input().split()]
	s = [int(j) for j in input().split()]
	a = sum(s)
	print(min(a, m))


n = int(input())
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	q = list(map(int, input().split()))
	print(min(b, sum(q)))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	E = 0
	for j in range(1, n):
		E += a[j]
	print(min(m, a[0] + E))


import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	sum = 0
	for i in a:
		sum += i
	if sum >= m:
		print(m)
	else:
		print(math.ceil(sum))


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin, tan

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline()
for _ in range(ii()):
	(n, m) = mi()
	a = li()
	s = sum(a[1:])
	print(min(a[0] + s, m))


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	print(min(s, m))


T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	al = sum(arr)
	print(min(m, al))


t = int(input())
while t:
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = 0
	for i in range(1, n):
		ans += l[i]
	if l[0] + ans < m:
		print(l[0] + ans)
	else:
		print(m)
	t -= 1


numCases = int(input())
for x in range(numCases):
	m = int(input().split()[1])
	nums = [*map(int, input().split())]
	total = sum(nums)
	if total < m:
		print(total)
	else:
		print(m)


import sys
readLine = lambda : sys.stdin.readline()
readInt = lambda : int(sys.stdin.readline())
readInts = lambda : [int(x) for x in sys.stdin.readline().split(' ')]

def main():
	solns = []
	t = readInt()
	for _ in range(t):
		(n, m) = readInts()
		arr = readInts()
		solns.append(m if sum(arr) > m else sum(arr))
	print('\n'.join((str(x) for x in solns)))
main()


t = int(input())
ls = [list(map(int, input().split())) for _ in range(2 * t)]
nm = []
a = []
for i in range(2 * t):
	if i % 2 == 0:
		nm.append(ls[i])
	elif i % 2 == 1:
		a.append(ls[i])
for j in range(t):
	if sum(a[j]) <= nm[j][1]:
		print(sum(a[j]))
	elif sum(a[j]) > nm[j][1]:
		print(nm[j][1])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ar = [int(x) for x in input().split()]
	sm = 0
	for i in range(1, n):
		sm += ar[i]
	if sm + ar[0] > m:
		print(m)
	else:
		print(ar[0] + sm)


ax = ord('a')
ttt = int(input())
while ttt:
	ttt -= 1
	nm = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	for i in range(1, nm[0]):
		if a[0] >= nm[1]:
			break
		d = min(nm[1] - a[0], a[i])
		a[0] += d
	print(a[0])


from math import *
t = int(input())
for y in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	print(min(k, s))


t = int(input())
while t != 0:
	t -= 1
	(n, m) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	ans = 0
	for i in arr:
		ans += i
	if ans > m:
		print(m)
	else:
		print(ans)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	list1 = list(map(int, input().split()))
	sum1 = 0
	for i in list1:
		sum1 += i
	if sum1 >= m:
		print(m)
	else:
		print(sum1)


def highest_score():
	s1 = input().split(' ')
	n = int(s1[0])
	m = int(s1[1])
	s2 = input().split(' ')
	score = 0
	for i in s2:
		score += int(i)
	if score > m:
		print(m)
	else:
		print(score)
row = int(input())
for r in range(row):
	highest_score()


arr = []
t = int(input())
for ti in range(t):
	[n, m] = [int(x) for x in input().split()]
	marks = [int(x) for x in input().split()]
	k = sum(marks)
	mark = m if k > m else k
	arr.append(mark)
for x in arr:
	print(x)


r = lambda : [*map(int, input().split())]
exec(r()[0] * 'print(min(r()[1],sum(r())));')


for _ in range(int(input())):
	(_, m) = map(int, input().split())
	scores = list(map(int, input().split()))
	total = sum(scores[1:])
	print(min(m, scores[0] + total))


t = int(input())
for q in range(t):
	nm = input().split(' ')
	n = int(nm[0])
	m = int(nm[1])
	a = input().split(' ')
	yo = 0
	for e in range(len(a)):
		yo += int(a[e])
	print(min(yo, m))


t = int(input())
for i in range(t):
	(N, M) = map(int, input().split())
	A = list(map(int, input().split()))
	S = sum(A)
	if S >= M:
		print(M)
	else:
		print(S)


from math import *
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	s = 0
	for i in range(n):
		s = s + l[i]
		if s > m:
			print(m)
			break
	else:
		print(s)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split(' '))
	array = map(int, input().split(' '))
	sm = sum(array)
	print(min(sm, m))


for i in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	ans = min(arr[0] + sum(arr[1:]), b)
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	scores = list(map(int, input().split()))
	total = sum(scores)
	mean = total // n
	others = total - scores[0]
	diff = m - scores[0]
	if diff < others:
		print(m)
	else:
		print(scores[0] + others)


t = int(input())
for q in range(t):
	(n, m) = map(int, input().split())
	scores = [int(x) for x in input().split()]
	myscore = scores[0]
	diff = m - myscore
	s = sum(scores[1:])
	if myscore == m:
		print(m)
	elif diff <= s:
		print(m)
	else:
		print(myscore + s)


t = int(input())

def solve(n, m, a):
	tot = sum(a) - a[0]
	tmp = m - a[0]
	if tmp < tot:
		return m
	else:
		return a[0] + tot
ans = []
for _ in range(t):
	(tn, tm) = map(int, input().split())
	ta = list(map(int, input().split()))
	ans.append(solve(tn, tm, ta))
for a in ans:
	print(a)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	sum1 = sum(l)
	print(min(m, sum1))


def main():
	data = []
	n_tasks = int(input())
	for _ in range(n_tasks):
		(n, m) = map(int, input().split())
		marks_list = list(map(int, input().split()))
		data.append([n, m, marks_list])
	for task in data:
		n = task[0]
		m = task[1]
		marks_list = task[2]
		print(min(m, sum(marks_list)))
main()


t = int(input())
for __ in range(t):
	(n, m) = map(int, str(input()).split())
	l = [int(x) for x in input().split()]
	if sum(l) >= m:
		print(m)
	else:
		print(sum(l))


t = int(input())
m = []
a = []
for i in range(t):
	tmp = list(map(int, input().split(' ')))
	m.append(tmp[1])
	a.append(list(map(int, input().split(' '))))
for i in range(t):
	s = sum(a[i])
	if m[i] > s:
		print(s)
	else:
		print(m[i])


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	n = I()
	ans = []
	for _ in range(n):
		(k, m) = LI()
		l = LI()
		sm = sum(l)
		ans.append(min(m, sm))
	for x in ans:
		print(x)
main()


def max_score(n, m, scores):
	total = sum(scores)
	return m if total > m else total
t = int(input())
ans = []
for i in range(t):
	first = input().split(' ')
	second = input().split(' ')
	scores = [int(i) for i in second]
	(n, m) = (int(first[0]), int(first[1]))
	ans.append(max_score(n, m, scores))
for i in ans:
	print(i)


import math
t = int(input())
for z in range(t):
	(n, m) = map(int, input().split())
	som = sum([int(i) for i in input().split()])
	if som <= m:
		print(som)
	else:
		print(m)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	av = sum(l) / n
	if n == 1:
		print(l[0])
	elif sum(l) < m:
		print(sum(l))
	else:
		print(m)


t = int(input())
for i in range(t):
	inp = input().split(' ')
	scores = [int(x) for x in input().split(' ')]
	print(min(int(inp[1]), sum(scores)))


t = int(input())
for _ in range(t):
	(m, n) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	a.sort()
	tmp = sum(a[:-1])
	print([tmp + a[-1], n][n - a[-1] < tmp])


t1 = int(input())
for _ in range(t1):
	(n, x) = map(int, input().split())
	o = 0
	a = list(map(int, input().split()))
	if sum(a) > x:
		print(x)
	else:
		print(sum(a))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().strip().split()))
	my = l[0]
	s = sum(l)
	print(min(s, m))


t = int(input())
while t:
	(n, max) = map(int, input().split())
	arr = list(map(int, input().split()))
	total = sum(arr)
	if max <= total:
		arr[0] = max
		total = total - max
	else:
		arr[0] = total
		total = 0
	if total > 0:
		arr[1:] = [0] * (len(arr) - 1)
		for i in range(1, n - 1):
			if total != 0:
				arr[i] = arr[i] + 1
				total -= 1
			i = i + 1
			if i == n - 1:
				arr[n - 1] = total
	else:
		arr[1:] = [0] * (len(arr) - 1)
	print(arr[0])
	t -= 1


for __ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	print(min(sum(l), m))


t = int(input())
for i in range(t):
	s = 0
	n = list(map(int, input().split()))
	s = list(map(int, input().split()))
	print(min(n[1], sum(s)))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	nums = list(map(int, input().split()))
	me = nums[0]
	for i in range(1, n):
		if me + nums[i] < m:
			me += nums[i]
			nums[i] = 0
		else:
			me += nums[i]
			me = me - (me - m)
			break
	print(me)


t = int(input())
while t > 0:
	(m, n) = map(int, input().split())
	s = list(map(int, input().strip().split()))[:m]
	score = 0
	for i in range(1, m):
		if s[0] + s[i] < n:
			s[0] += s[i]
		else:
			s[0] = n
			break
	print(s[0])
	t = t - 1


import sys
import bisect
import heapq
from math import *
from collections import defaultdict as dd
from collections import deque
from collections import Counter as c
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(var)

def l():
	return list(map(int, data().split()))

def sl():
	return list(map(str, data().split()))

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [[val for i in range(n)] for j in range(m)]
for _ in range(int(data())):
	(n, m) = sp()
	arr = l()
	answer = 0
	for i in range(1, n):
		answer += arr[i]
	print(min(m, answer + arr[0]))


for _ in range(int(input())):
	(nb_student, max_mark) = [int(x) for x in input().split()]
	marks = [int(x) for x in input().split()]
	print(min(sum(marks), max_mark))


t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	a = [int(i) for i in input().split()]
	print(a[0] + min(sum(a[1:]), m - a[0]))


t = int(input())
while t:
	t -= 1
	(n, a) = input().split()
	n = int(n)
	a = int(a)
	list = [int(i) for i in input().split()]
	total = sum(list)
	if total >= a:
		print(a)
	else:
		print(total)


def solve():
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	print(min(sum(l), m))
t = int(input())
for _ in range(t):
	solve()


def R():
	return map(int, input().split())

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
import bisect
for i in range(I()):
	(n, m) = R()
	a = L()
	print(min(m, sum(a)))


n = int(input())
for i in range(n):
	m = list(map(int, input().split()))
	(stu, high) = (m[0], m[1])
	scores = list(map(int, input().split()))
	if sum(scores) == high:
		print(sum(scores))
	elif sum(scores) < high:
		print(sum(scores))
	else:
		print(high)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def solve():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = min(sum(a), m)
	print(ans)
t = int(input())
for i in range(t):
	solve()


def solve():
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	S = sum(A)
	print(min(S, m))
T = int(input())
while T > 0:
	T -= 1
	solve()


for i in range(int(input())):
	(n, m) = map(int, input().split())
	marks = list(map(int, input().split()))
	if sum(marks) >= m:
		print(m)
	else:
		print(sum(marks))


t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	if s >= y:
		print(y)
	else:
		print(s)


T = int(input())
for i in range(T):
	(n, m) = map(int, input().split())
	points = list(map(int, input().split()))
	summ = sum(points)
	first = points[0]
	del points[0]
	summ_new = sum(points)
	max_point = first + summ_new
	if max_point >= m:
		print(m)
	else:
		print(max_point)


import math
nirvana = int(input())
for i in range(nirvana):
	(x, n) = map(int, input().split())
	c = list(map(int, input().split()))
	k = min(n, sum(c))
	print(k)


t = int(input())
res = []
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	k = sum(a)
	if k >= m:
		res.append(m)
	else:
		res.append(k)
for i in range(len(res)):
	print(res[i])


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = [int(j) for j in input().split()]
	s = sum(a[1:n])
	if s + a[0] >= m:
		print(m)
	else:
		print(s + a[0])


n = int(input())
for _ in range(n):
	(n1, n2) = map(int, input().split())
	l = list(map(int, input().split()))
	m = sum(l)
	if m > n2:
		print(n2)
	else:
		print(m)


for _ in [0] * int(input()):
	n = list(map(int, input().split()))
	mx = list(map(int, input().split()))
	ocenk = sum(mx)
	if ocenk > n[1]:
		print(n[1])
	else:
		print(ocenk)


t = int(input())
for _ in range(t):
	(n, m) = (int(i) for i in input().split())
	a = (int(i) for i in input().split())
	res = min(m, sum(a))
	print(res)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	ar = list(map(int, input().split()))
	j = ar[0]
	if sum(ar) - j > m - j:
		print(m)
	else:
		print(sum(ar))


from sys import stdin
a = int(stdin.readline())
for k in range(0, a):
	b = stdin.readline().split()
	A = int(b[0])
	B = int(b[1])
	sum = 0
	C = stdin.readline().split()
	for c in range(0, A):
		sum = sum + int(C[c])
	print(min(sum, B))


t = int(input())
for _ in range(t):
	ip = list(map(int, input().split()))
	(n, m) = (ip[0], ip[1])
	score = list(map(int, input().split()))
	if score[0] < m:
		for j in range(1, n):
			if score[0] + score[j] <= m:
				score[0] = score[0] + score[j]
				score[j] = 0
			else:
				score[0] = m
				break
	print(score[0])


test_cases = int(input())
for i in range(test_cases):
	first_line = input().split(' ')
	grades = input().split(' ')
	number_of_students = int(first_line[0])
	highest_grade_possible = int(first_line[1])
	soma = 0
	for i in range(number_of_students):
		grades[i] = int(grades[i])
		soma += grades[i]
	print(min(highest_grade_possible, soma))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	students = list(map(int, input().split()))
	me = students[0]
	my_new_score = me
	rest = m - me
	others_sum = 0
	for i in range(1, n):
		if students[i] - rest < 0:
			rest -= students[i]
		else:
			rest = 0
			break
	if rest > 0:
		print(m - rest)
	else:
		print(m)


from sys import *
input = stdin.readline
t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	print(min(m, sum(a)))
	t -= 1


n = int(input())
for i in range(n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	x = [int(x) for x in input().split()]
	if sum(x) > b:
		print(b)
	else:
		print(sum(x))


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(N, K) = MAP()
	A = LIST()
	print(min(sum(A), K))


def rint():
	return int(input())

def rlint():
	return list(map(int, input().split()))
t = rint()
for _ in range(t):
	(n, m) = rlint()
	a = rlint()
	print(min(sum(a), m))


read = lambda : list(map(int, input().split()))
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = read()
	sumer = sum(arr)
	if m < sumer:
		print(m)
	else:
		print(sumer)


for _ in range(int(input())):
	n = list(map(int, input().split()))
	m = list(map(int, input().split()))
	b = sum(m)
	if b > n[1]:
		print(n[1])
	else:
		print(b)


s = int(input())
for i in range(s):
	(n, m) = map(int, input().split())
	l = [int(k) for k in input().split()]
	ans = 0
	for j in range(n):
		ans += l[j]
	print(min(m, ans))


t = int(input())
for i in range(t):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	array = []
	array = input().split()
	for i in range(n):
		array[i] = int(array[i])
	for j in range(n - 1):
		while array[j + 1] > 0 and array[0] + 1 <= m:
			array[j + 1] = array[j + 1] - 1
			array[0] = array[0] + 1
	print(array[0])


(a, I) = ([], input)
for _ in range(int(I())):
	(n, m) = map(int, I().split())
	l = list(map(int, I().split()))
	if sum(l) >= m:
		a.append(m)
	else:
		a.append(sum(l))
for i in a:
	print(i)


T = int(input().strip())
for t in range(T):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	s = sum(A)
	needToMax = m - A[0]
	if needToMax == 0:
		print(A[0])
	elif s - A[0] >= needToMax:
		print(m)
	else:
		print(s)


for u in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	print(min(k, s))


z = []
n = int(input())
for i in range(n):
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	if sum(b) >= a[1]:
		z.append(a[1])
	else:
		z.append(sum(b))
for i in z:
	print(i)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(n, m) = [int(b) for b in sys.stdin.readline().split()]
	aq = [int(b) for b in sys.stdin.readline().split()]
	s = sum(aq[1:])
	s = min(m, s + aq[0])
	print(s)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	sum1 = l[0]
	for i in range(1, n):
		if sum1 < m:
			sum1 += l[i]
	print(min(sum1, m))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().strip().split()))[:n]
	if sum(arr) >= k:
		print(k)
	else:
		print(sum(arr))


t = int(input())
for i in range(t):
	(students, maximum) = [int(x) for x in input().split()]
	array = [int(x) for x in input().split()]
	total = sum(array)
	print(min(total, maximum))


t = int(input())
while t != 0:
	t -= 1
	(n, m) = tuple(map(int, input().split()))
	a = list(map(int, input().split()))
	s = sum(a)
	if s >= m:
		print(m)
	else:
		print(s)


t = int(input())
while t > 0:
	t -= 1
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) >= m:
		print(m)
	else:
		sum__ = 0
		for i in sorted(a):
			if sum__ <= m:
				sum__ += i
			else:
				break
		print(sum__)


t = int(input())
while t > 0:
	(x, y) = map(int, input().split())
	A = list(map(int, input().split()))
	sum = 0
	for i in range(len(A)):
		sum += A[i]
	print(min(sum, y))
	t -= 1


import statistics
q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	maxpossible = min(sum(a), m)
	mean = statistics.mean(a)
	print(maxpossible)


s = int(input())
while s:
	lis = list(map(int, input().split()))
	a = list(map(int, input().split()))
	total = sum(a) - a[0]
	if lis[1] - a[0] <= total:
		print(lis[1])
	else:
		print(total + a[0])
	s -= 1


from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 500010
MOD = 10 ** 9 + 7
spf = [i for i in range(MAXN)]
spf[0] = spf[1] = -1

def sieve():
	for i in range(2, MAXN, 2):
		spf[i] = 2
	for i in range(3, int(MAXN ** 0.5) + 1):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def fib(n, m):
	if n == 0:
		return [0, 1]
	else:
		(a, b) = fib(n // 2)
		c = a % m * (b % m * 2 - a % m) % m
		d = a % m * (a % m) % m + b % m * b % m % m
		if n % 2 == 0:
			return [c, d]
		else:
			return [d, c + d]

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def ncr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % MOD
		den = den * (i + 1) % MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def flush():
	return sys.stdout.flush()
for _ in range(int(input())):
	(n, m) = arrIN()
	a = arrIN()
	s = sum(a)
	while m / n > s / n:
		m -= 1
	print(m)


t = int(input())
for it in range(t):
	(n, m) = (int(val) for val in input().split())
	a = [int(n) for n in input().split()]
	res = 0
	for n in a:
		res += n
	print(min(res, m))


n = int(input())
c = 0
for i in range(n):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for j in b:
		c += j
	print(min(c, a[1]))
	c = 0


def main():
	op = ''
	t = int(input())
	for i in range(t):
		(n, m) = map(int, input().split(' '))
		ip = [int(item) for item in input().split(' ')]
		sum_n = sum(ip[1:])
		if ip[0] + sum_n <= m:
			op += str(ip[0] + sum_n) + '\n'
		else:
			op += str(m) + '\n'
	print(op)
main()


for t in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	l = [int(i) for i in input().split()]
	b = sum(l) / n
	while m / n > b:
		m -= 1
	print(m)


for tc in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	ss = sum(l) - l[0]
	d = m - l[0]
	if ss >= d:
		print(m)
	else:
		print(l[0] + ss)


t = int(input())
while t != 0:
	(m, n) = map(int, input().split())
	lst = input().split()
	sum = 0
	for num in lst:
		sum += int(num)
	if sum < n:
		print(sum)
	else:
		print(n)
	t = t - 1


testcases = int(input())
megal = []
for i in range(testcases):
	nohi = tuple(map(int, input().split(' ')))
	scores = tuple(map(int, input().split(' ')))
	megal.append((nohi, scores))

def calc(tup):
	high = tup[0][1]
	scores = tup[1]
	summ = sum(scores) - scores[0]
	val = high - scores[0]
	if summ >= val:
		return high
	else:
		return scores[0] + summ
for i in megal:
	print(calc(i))


import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(input())

def read_int_n():
	return list(map(int, input().split()))

def read_float():
	return float(input())

def read_float_n():
	return list(map(float, input().split()))

def read_str():
	return input().strip()

def read_str_n():
	return list(map(str, input().split()))

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

@mt
def slv(N, M, A):
	sa = sum(A)
	a1 = min(M, sa)
	return a1

def main():
	T = read_int()
	for _ in range(T):
		(N, M) = read_int_n()
		A = read_int_n()
		print(slv(N, M, A))
main()


def solve():
	t = int(input())
	for i in range(t):
		(n, m) = [int(s) for s in input().split()]
		a = [int(s) for s in input().split()]
		s = sum(a)
		print(min(s, m))
solve()


t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	inp = list(map(int, input().split()))
	t -= 1
	if sum(inp) >= m:
		print(m)
	else:
		print(int(sum(inp)))


t = int(input())
while t > 0:
	t -= 1
	(ns, m) = map(int, input().split())
	students = list(map(int, input().split()))
	avg = sum(students) / ns
	diff_students = sum(students) - students[0]
	max_add = students[0]
	for i in range(m, 0, -1):
		if diff_students - (i - students[0]) >= 0:
			max_add = i
			break
	print(max_add)


T = int(input())
for i in range(0, T):
	(N, M) = input().split()
	N = int(N)
	M = int(M)
	l = [int(n) for n in input().split()]
	if sum(l) >= M:
		print(M)
	else:
		print(sum(l))


test_case = int(input())
t = 0
while t < test_case:
	inp = input()
	n = list(map(int, inp.split()))
	max1 = n[1]
	inpscores = input()
	scores = list(map(int, inpscores.split()))
	average = sum(scores) / n[0]
	temp = scores[0]
	while max1 >= 0:
		diff = max1 - scores[0]
		if sum(scores[1:len(scores)]) >= diff:
			scores[0] = max1
			max1 = -1
		elif sum(scores[1:len(scores)]) == 0:
			max1 = -1
		else:
			scores[0] = sum(scores)
			max1 = -1
	print(scores[0])
	t = t + 1


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = 0
	for i in range(1, n):
		s += a[i]
	ans = min(a[0] + s, m)
	print(ans)


t = int(input())
while t > 0:
	l = [int(i) for i in input().split()]
	n = l[0]
	m = l[1]
	marks = [int(i) for i in input().split()]
	s = sum(marks[1:])
	if s + marks[0] > m:
		print(m)
		t -= 1
		continue
	print(s + marks[0])
	t -= 1


t = int(input())
i = 0
for i in range(t):
	a = list(map(int, input().split()))
	n = a[0]
	k = a[1]
	a = list(map(int, input().split()))
	j = 0
	sum = 0
	for j in range(n):
		sum += a[j]
	if k <= sum:
		print(k)
	else:
		print(sum)


def main():
	t = int(input())
	for i in range(t):
		list = input().split()
		n = int(list[0])
		m = int(list[1])
		vec = [int(x) for x in input().split()]
		sum = 0
		for j in range(n):
			sum += vec[j]
		if sum > m:
			print(m)
		else:
			print(sum)
main()


for i in range(int(input())):
	(n, m) = map(int, input().split())
	mas = list(map(int, input().split()))
	ans = mas[0]
	mas = mas[1:]
	if sum(mas) + ans >= m:
		print(m)
	else:
		print(ans + sum(mas))


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	s = list(map(int, input().split()))
	sum1 = s[0]
	i = 1
	while i < n:
		if sum1 + s[i] <= m:
			sum1 = sum1 + s[i]
		else:
			sum1 = m
			break
		i = i + 1
	print(sum1)


t = int(input())
for i in range(t):
	sum = 0
	(student, max_marks) = map(int, input().split())
	marks = list(map(int, input().split()))
	for j in range(1, student):
		while marks[j] != 0:
			if marks[0] != max_marks:
				marks[0] += 1
				marks[j] -= 1
			else:
				break
		if marks[0] == max_marks:
			break
	print(marks[0])


def ini():
	n = input()
	return int(n)
testCase = ini()
while testCase > 0:
	testCase -= 1
	(n, m) = (int(i) for i in input().split())
	l = (int(i) for i in input().split())
	print(min(m, sum(l)))


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	(n, m) = invr()
	ara = inara()
	for i in range(1, n):
		ara[0] += ara[i]
	ara[0] = min(m, ara[0])
	print(ara[0])


t = int(input())
l2 = []
for i in range(t):
	(n, m) = map(int, input().split())
	l1 = [int(a) for a in input().split()]
	a = l1[0]
	s = 0
	for k in range(0, n):
		s += l1[k]
	s = s - a
	j = m - a
	if s >= j:
		l2.append(m)
	else:
		l2.append(a + s)
for i in range(t):
	print(l2[i])


q = int(input())
for rwer in range(q):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	print(min(m, sum(l)))


for i in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	h = l.pop(0)
	g = sum(l)
	f = m - h
	if f == 0 or f <= g:
		print(m)
	else:
		print(h + g)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	if s > m:
		print(m)
	else:
		print(s)


t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	avg = sum(a) / n
	sum_rem = sum(a[1:])
	if a[0] + sum_rem >= m:
		print(m)
	else:
		print(a[0] + sum_rem)
	t -= 1


import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	sum = 0
	for i in range(n):
		sum += arr[i]
	print(min(sum, m))


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	s = sum(c)
	if s >= b:
		print(b)
	else:
		print(s)


try:
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		l = list(map(int, input().split()))
		a = sum(l) / m
		if a >= 1:
			print(m)
		else:
			print(sum(l))
except:
	pass


def gradeAllocation(nums, m):
	return min(m, sum(nums))
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	nums = list(map(int, input().split()))
	print(gradeAllocation(nums, m))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	s = 0
	for j in range(n):
		s += l[j]
	q = s / n
	print(min(s, m))


def solve():
	(n, m) = map(int, input().split())
	l1 = list(map(int, input().split()))
	t = sum(l1)
	if t > m:
		print(m)
	else:
		print(t)
for _ in range(int(input())):
	solve()


a = int(input())
for i in range(a):
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	summ = 0
	for p in c:
		summ += p
	if summ > b[1]:
		print(b[1])
	else:
		print(summ)


x = int(input())
for x in range(x):
	vet = list(map(int, input().split(' ')))
	alunos = vet[0]
	nota = vet[1]
	scores = list(map(int, input().split(' ')))
	st = 0
	for i in range(len(scores)):
		st += scores[i]
	if st == nota:
		print(st)
	elif st > nota:
		print(nota)
	else:
		print(st)


num_cases = int(input())
data_dictionary = {}
for case_number in range(1, num_cases + 1):
	line_1 = input()
	line_2 = input()
	data_dictionary[case_number] = {'n': int(line_1.split()[0]), 'm': int(line_1.split()[1]), 'a': [int(x) for x in line_2.split()]}

def compute_highest_score(a, m):
	return min(sum(a), m)
for case in data_dictionary:
	a = data_dictionary[case]['a']
	m = data_dictionary[case]['m']
	print(compute_highest_score(a, m))


t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	scoreList = [int(x) for x in input().split()]
	target = m - scoreList[0]
	if target == 0:
		print(m)
	else:
		i = 1
		currentSum = 0
		while i < n and currentSum < target:
			currentSum += scoreList[i]
			i += 1
		if currentSum < target:
			print(currentSum + scoreList[0])
		else:
			print(m)
	t -= 1


T = int(input())
for i in range(T):
	nm = input().split()
	n = int(nm[0])
	m = int(nm[1])
	marks = list(map(int, input().split()))
	s = sum(marks)
	print(min(s, m))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = [int(k) for k in input().split()]
	sumi = 0
	for i in range(n):
		sumi = sumi + arr[i]
	if sumi >= m:
		print(m)
	else:
		print(sumi)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	s1 = list(map(int, input().split()))
	c = min(sum(s1), m)
	print(c)


def ii():
	return int(input())

def mii():
	return map(int, input().split())

def lmii():
	return list(mii())

def main():
	for _ in range(ii()):
		(r, m) = mii()
		a = lmii()
		print(sum(a) if m > sum(a) else m)
main()


for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	s = 0
	for j in range(len(l)):
		s += l[j]
	if s >= b:
		print(b)
	else:
		print(s)


t = int(input())
for i in range(t):
	(n, m) = (int(x) for x in input().split(' '))
	scores = [int(x) for x in input().split(' ')]
	my_score = scores[0]
	score_needing = m - my_score
	other_scores = sum(scores[1:])
	if other_scores >= score_needing:
		print(m)
	else:
		print(other_scores + my_score)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	diff = m - arr[0]
	if sum(arr[1:]) >= diff:
		print(m)
	else:
		d = sum(arr[1:])
		print(d + arr[0])


try:
	t = int(input())
	for _ in range(t):
		(n, m) = list(map(int, input().split()))
		arr = list(map(int, input().split()))
		sum = 0
		for i in range(1, n):
			sum += arr[i]
		if arr[0] + sum >= m:
			print(m)
		else:
			print(arr[0] + sum)
except:
	pass


def solve(m, A):
	return min(m, sum(A))
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	r = solve(m, A)
	print(r)


testes = int(input())
for t in range(testes):
	ent = input().split(' ')
	alunos = int(ent[0])
	maxima = int(ent[1])
	notas = list(map(int, input().split(' ')))
	minha = notas[0]
	notas.remove(notas[0])
	dif = maxima - minha
	flag = True
	i = 0
	while dif > 0 and i < len(notas):
		atual = notas[i]
		minha += atual
		dif = maxima - minha
		i += 1
	if minha >= maxima:
		print(maxima)
	else:
		print(minha)


import sys
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	s = [int(i) for i in input().split()]
	print(min(sum(s), m))


tests = int(input())
for i in range(tests):
	(students, highest) = list(map(int, input().split()))
	scores = list(map(int, input().split()))
	difference = highest - scores[0]
	me = scores[0]
	if difference == 0:
		print(me)
	else:
		scores.pop(0)
		potential = sum(scores)
		if potential >= difference:
			print(highest)
		else:
			print(potential + me)


def solve():
	(n, m) = map(int, input().split())
	li = list(map(int, input().split()))
	s = sum(li)
	for i in range(n):
		if s == 0:
			li[i] = 0
		elif s >= m:
			li[i] = m
			s -= m
		elif s < m:
			li[i] = s
			s = 0
	print(li[0])
t = int(input())
for _ in range(t):
	solve()


def checker(m, lst):
	return min(m, sum(lst))
for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	print(checker(m, a))


qtd = int(input())
for i in range(0, qtd):
	(qtdalunos, notamaxima) = list(map(int, input().split()))
	notas = list(map(int, input().split()))
	soma = sum(notas)
	if soma > notamaxima:
		print(notamaxima)
	else:
		print(soma)


t = int(input())
for j in range(t):
	(n, m) = list(map(int, input().split()))
	v = list(map(int, input().split()))
	soma = sum(v)
	if soma >= m:
		print(m)
	else:
		print(soma)


t = int(input())
for i in range(t):
	m = input().split()
	m0 = int(m[0])
	m1 = int(m[1])
	n = input().split()
	sum = 0
	for i in range(len(n)):
		n[i] = int(n[i])
		sum += n[i]
	if sum >= m1:
		print(m1)
	else:
		print(sum)


t = int(input())
for i in range(t):
	(n, m) = input().split()
	m = int(m)
	a_list = [int(a) for a in input().split()]
	grade = a_list[0]
	for a in a_list[1:]:
		if a + grade >= m:
			grade = m
			break
		grade += a
	print(grade)


case = int(input())
for i in range(case):
	(n, m) = (int(v) for v in input().split())
	list1 = [int(u) for u in input().split()]
	total = 0
	for j in range(len(list1)):
		total += list1[j]
		if total >= m:
			print(m)
			break
		else:
			continue
	if total < m:
		print(total)
	else:
		pass


import sys
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, size, link):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().split()))
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	(n, m) = int_array()
	a = int_array()
	if n == 1:
		print(a[0])
	else:
		a.sort()
		mine = a[-1]
		mine += sum(a[:-1])
		print(min(m, mine))


for useless in range(int(input())):
	(n, m) = map(int, input().split())
	s = map(int, input().split())
	s = sum(s)
	print(min(m, s))


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, m) = [int(x) for x in stdin.readline().split()]
	arr = [int(x) for x in stdin.readline().split()]
	ans = 0
	for i in range(n - 1, 0, -1):
		taken = min(m - arr[0] - ans, arr[i])
		arr[i] -= taken
		ans += taken
	print(arr[0] + ans)


tc = int(input())
for _ in range(tc):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	s = sum(ar[1:])
	print(min(k, s + ar[0]))


from sys import stdin
t = int(stdin.readline())
for i in range(t):
	(n, m) = list(map(int, stdin.readline().split(' ')))
	A = list(map(int, stdin.readline().split(' ')))
	origin_score = A[0]
	for score in A[1:]:
		origin_score += score
		if origin_score >= m:
			origin_score = m
			break
	print(origin_score)


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	As = list(map(int, input().split()))
	my = As[0]
	other = As[1:]
	total = sum(other)
	print(min(m, my + total))


def maxSelfGrade(n, m, arr):
	if sum(arr) >= m:
		return m
	else:
		return sum(arr)
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(maxSelfGrade(n, m, arr))


n = int(input())
for i in range(n):
	(num_students, max_grade) = map(int, input().split(' '))
	total = sum(map(int, input().split(' ')))
	print(total if total < max_grade else max_grade)


p = int(input())
for i in range(p):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	print(min(b, sum(l)))


for i in range(int(input())):
	a = list(map(int, input().strip().split()))[:2]
	b = list(map(int, input().strip().split()))[:a[0]]
	sum = 0
	for k in b:
		sum += k
	if sum > a[1]:
		print(a[1])
	else:
		print(sum)


t = int(input(''))
for i in range(t):
	s = input('')
	L = s.split(' ')
	(n, m) = (int(L[0]), int(L[1]))
	s1 = input('')
	L1 = s1.split(' ')
	sume = 0
	for i in range(1, n):
		sume += int(L1[i])
	if sume > m - int(L1[0]):
		print(m)
	else:
		print(sume + int(L1[0]))


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def solve():
	(n, m) = rl()
	A = rl()
	s = sum(A)
	print(min(m, s))
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


import sys
input = sys.stdin.readline
T = int(input())
for tc in range(T):
	(n, m) = map(int, input().split())
	nl = list(map(int, input().split()))
	r = sum(nl)
	print(r if r <= m else m)


t = int(input())
while t:
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	sum1 = 0
	for i in l:
		sum1 = sum1 + i
	if sum1 >= m:
		l1 = m
	else:
		l1 = sum1
	print(l1)
	t = t - 1


r = lambda : map(int, input().split())
exec(int(input()) * 'n,m=r();print(min(m,sum(map(int,input().split()))));')


t = int(input())
l1 = []
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) >= m:
		l1.append(m)
	else:
		l1.append(sum(a))
for item in l1:
	print(item)


def f():
	(n, m) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	if m <= sum(a):
		print(m)
	else:
		print(sum(a))
for i in range(int(input())):
	f()


try:
	for i in range(int(input())):
		(n, m) = map(int, input().split())
		w = list(map(int, input().split()))
		print(min(m, sum(w)))
except:
	pass


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	lis = list(map(int, input().split()))
	print(min(m, sum(lis)))


import sys
import math
import bisect

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		A = list(map(int, input().split()))
		print(min(m, sum(A)))
main()


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	lst = list(map(int, input().split()))
	print(min(sum(lst), b))


t = int(input())
for tt in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	print(min(s, m))


from sys import stdin, stdout
t = int(input())
while t > 0:
	(n, m) = map(int, stdin.readline().rstrip().split())
	score = list(map(int, input().strip().split()))[:n]
	list_sum = sum(score)
	print(min(list_sum, m))
	t = t - 1


t = int(input())
R = lambda : map(int, input().split())
for i in range(t):
	(n, m) = R()
	a = list(R())
	print(min(m, sum(a)))


test = int(input())
for i in range(test):
	(n, m) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	if n == 1:
		print(*arr)
	else:
		restSum = sum(arr[1:])
		possibleVal = m - arr[0]
		if restSum >= possibleVal:
			print(m)
		else:
			print(restSum + arr[0])


a = int(input())
for i in range(a):
	h = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k = sum(b)
	if k > h[1]:
		print(h[1])
	else:
		print(k)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(int(inp())):
	(n, m) = mp()
	arr = lmp()
	print(min(sum(arr), m))


def solve():
	(x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	print(min(y, sum(a)))
for i in range(int(input())):
	solve()


t = int(input())
for i in range(t):
	(num, highest_score) = [int(x) for x in input().split()]
	a = list(map(int, input().split()))
	sum = 0
	for j in range(len(a)):
		sum += a[j]
		if sum > highest_score:
			print(highest_score)
			break
	if sum <= highest_score:
		print(sum)


for __ in range(int(input())):
	(b, c) = map(int, input().split())
	x = [int(i) for i in input().split()]
	if sum(x) >= c:
		print(c)
	else:
		print(sum(x))


t = int(input())
while t:
	t -= 1
	(_, m) = map(int, input().split())
	print(min(sum(map(int, input().split())), m))


def main():
	t = int(input())
	for i in range(t):
		(n, m) = list(map(int, input().split()))
		a = list(map(int, input().split()))
		s = sum(a)
		a = determine(a, s, m)
		print(a)

def determine(a, s, m):
	if s <= m:
		return s
	else:
		return m
main()


testcases = int(input())
for j in range(testcases):
	values = list(map(int, input().split()))
	numstudents = values[0]
	highest = values[1]
	scores = list(map(int, input().split()))
	score = sum(scores)
	if score <= highest:
		print(score)
	else:
		print(highest)


from functools import reduce

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(delimiter=' '):
		return input().split(delimiter)

	@staticmethod
	def list_int(delimiter=' '):
		return list(map(int, input().split(delimiter)))

def main():
	t = Read.int()
	for _ in range(t):
		(n, m) = Read.list_int()
		a = Read.list_int()
		i = 1
		while a[0] < m and i < n:
			if a[0] + a[i] < m:
				a[0] = a[0] + a[i]
			else:
				a[0] = m
			i += 1
		print(a[0])
main()


k = int(input())
arr = []
for i in range(k):
	m = input()
	m = m.split()
	n = int(m[0])
	m = int(m[1])
	a = []
	p = input()
	p = p.split()
	for j in range(n):
		a.append(int(p[j]))
	sum = 0
	for j in range(n):
		sum += a[j]
	if sum >= m:
		arr.append(m)
	else:
		arr.append(sum)
for i in range(k):
	print(arr[i])


t = int(input())
while t > 0:
	(n, m) = map(int, input().strip().split())
	score = map(int, input().strip().split())
	list_sum = sum(score)
	print(min(list_sum, m))
	t = t - 1


test_count = int(input())
for i in range(test_count):
	tot_scores = 0
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		tot_scores = tot_scores + a[i]
	if m >= tot_scores:
		print(tot_scores)
	else:
		print(m)


T_ON = 1
DEBUG_ON = 0
MOD = 998244353

def solve():
	(n, m) = read_ints()
	A = read_ints()
	print(min(m, sum(A)))

def main():
	T = read_int() if T_ON else 1
	for i in range(T):
		solve()

def debug(*xargs):
	if DEBUG_ON:
		print(*xargs)
from collections import *
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def read_int():
	return int(input())

def read_ints():
	return list(map(int, input().split()))

def print_nums(nums):
	print(' '.join(map(str, nums)))

def YES():
	print('YES')

def Yes():
	print('Yes')

def NO():
	print('NO')

def No():
	print('No')

def First():
	print('First')

def Second():
	print('Second')

def fib(n):
	(a, b) = (0, 1)
	for _ in range(n):
		(a, b) = (b, a + b)
	return a

def fib_ns(n):
	assert n >= 1
	f = [0 for _ in range(n + 1)]
	f[0] = 0
	f[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] + f[i - 2]
	return f

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def xgcd(a, b):
	(x0, x1, y0, y1) = (0, 1, 1, 0)
	while a != 0:
		((q, a), b) = (divmod(b, a), a)
		(y0, y1) = (y1, y0 - q * y1)
		(x0, x1) = (x1, x0 - q * x1)
	return (b, x0, y0)

def lcm(a, b):
	d = gcd(a, b)
	return a * b // d

def modinv(a, m):
	(g, x, _) = xgcd(a, m)
	if g != 1:
		raise Exception('gcd(a, m) != 1')
	return x % m

def mod_add(x, y):
	x += y
	while x >= MOD:
		x -= MOD
	while x < 0:
		x += MOD
	return x

def mod_mul(x, y):
	return x * y % MOD

def mod_pow(x, y):
	if y == 0:
		return 1
	if y % 2:
		return mod_mul(x, mod_pow(x, y - 1))
	p = mod_pow(x, y // 2)
	return mod_mul(p, p)

def mod_inv(y):
	return mod_pow(y, MOD - 2)

def mod_div(x, y):
	return mod_mul(x, mod_inv(y))

def is_prime(n):
	if n == 1:
		return False
	for i in range(2, int(n ** 0.5) + 1):
		if n % i:
			return False
	return True

def gen_primes(n):
	P = [True for _ in range(n + 1)]
	P[0] = P[1] = False
	for i in range(int(n ** 0.5) + 1):
		if P[i]:
			for j in range(2 * i, n + 1, i):
				P[j] = False
	return P
main()


n = int(input())
arr2 = []
for i in range(n):
	arr1 = list(map(int, input().split()))
	arr3 = list(map(int, input().split()))
	arr3.sort
	m = 0
	for j in range(arr1[0]):
		m = m + arr3[j]
	if m > arr1[1]:
		arr2.append(arr1[1])
	else:
		arr2.append(m)
for a in arr2:
	print(a)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	x = [int(f) for f in input().split()]
	b = sum(x[1:])
	if x[0] + b >= m:
		print(m)
	else:
		print(x[0] + b)


def gradeAllocation(n, m, A):
	for i in range(1, n):
		if A[i] + A[0] <= m:
			A[0] += A[i]
			A[i] = 0
		elif m - A[0] <= A[i]:
			A[0] = m
			A[i] -= m - A[0]
		if A[0] == m:
			break
	return A[0]
testCases = int(input())
while testCases:
	(n, m) = map(int, input().split())
	A = [int(val) for val in input().split()]
	print(gradeAllocation(n, m, A))
	testCases -= 1


n = int(input())
for i in range(n):
	n1 = list(map(int, input().split()))
	n2 = list(map(int, input().split()))
	if sum(n2) <= n1[1]:
		print(sum(n2))
	else:
		print(n1[1])


for i in range(int(input())):
	(n, m) = map(int, input().split())
	lst = [int(i) for i in input().split()]
	sm = sum(lst)
	if sm <= m:
		print(sm)
	else:
		print(m)


t = int(input())
for i in range(t):
	(n, mx) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	if mx <= s:
		print(mx)
	else:
		print(s)


t = int(input())
for i in range(t):
	(n, m) = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	ma = sum(a[1:])
	if a[0] + ma >= m:
		print(m)
	else:
		print(a[0] + ma)


from functools import reduce
t = int(input())
for i in range(0, t):
	nm = input().split()
	n = int(nm[0])
	m = int(nm[1])
	L = list(map(int, input().split()))
	s = reduce(lambda x, y: x + y, L)
	if s <= m:
		print(s)
	else:
		print(m)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a) - a[0]
	p = m - a[0]
	if s >= p:
		print(m)
	else:
		print(a[0] + s)


t = int(input())
while t > 0:
	t = t - 1
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	ms = m - a[0]
	s2 = sum(a[1:])
	if s2 >= ms:
		print(m)
	elif s2 < ms:
		print(a[0] + s2)


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	while A[0] < m:
		i = 1
		while i != n and A[i] == 0:
			i += 1
		if i == n:
			break
		A[0] += 1
		A[i] -= 1
	print(A[0])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ll = list(map(int, input().split()))
	s = sum(ll)
	if s >= k:
		print(k)
	else:
		print(s)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	if sum(l) >= m:
		print(m)
	elif sum(l) < m:
		print(sum(l))


num = int(input())
for i in range(num):
	(n, m) = map(int, input().split())
	li = list(map(int, input().split()))
	print(min(sum(li), m))


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	z = list(map(int, input().split()))
	if sum(z) >= b:
		print(b)
	else:
		print(sum(z))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = sum(l)
	if ans >= k:
		print(k)
	else:
		print(ans)


t = int(input())
while t > 0:
	(n, m) = input().split(' ')
	m = int(m)
	n = int(n)
	a = input().split(' ')
	s = 0
	for i in range(0, n, 1):
		s += int(a[i])
	if s <= m:
		a = s
	if s > m:
		a = m
	print(a)
	t -= 1


a = input()
b = int(a)
for _ in range(b):
	ball = input()
	arryoc = input()
	ballm = ball.split()
	arryocm = arryoc.split()
	maxball = int(ballm[1])
	midball = int(ballm[0])
	az = len(arryocm)
	res = 0
	for i in range(az):
		res += int(arryocm[i])
	if res > int(maxball):
		print(int(maxball))
	else:
		print(res)


cases = int(input().strip())
for case in range(cases):
	(n, m) = list(map(int, input().strip().split(' ')))
	a = list(map(int, input().strip().split(' ')))
	s = sum(a)
	print(min(m, s))


import sys
import os
from io import IOBase, BytesIO
import math
mod = 10 ** 9 + 7
pie = 3.1415926536

def modinv(n, p):
	return pow(n, p - 2, p)

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def ain():
	return list(map(int, sin().split()))

def sin():
	return input().strip()

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def read2DIntArray(row, col):
	arr = []
	for i in range(0, row):
		temp = list(map(int, sin().split()))
		arr.append(temp)
	return arr

def read2DCharArray(row, col):
	arr = []
	for i in range(0, row):
		temp = str(sin())
		arr.append(temp)
	return arr

def smallestNumber(n):
	lst = list(str(n))
	lst.sort()
	tmp = ''
	for (i, n) in enumerate(lst):
		if n != '0':
			tmp = lst.pop(i)
			break
	return str(tmp) + ''.join(lst)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	lst = []
	for p in range(n + 1):
		if prime[p]:
			lst.append(p)
	return lst

def nCr(n, r):
	a = 1
	b = 1
	c = 1
	for i in range(1, n + 1):
		c *= i
	for i in range(1, r + 1):
		b *= i
	for i in range(1, n - r + 1):
		a *= i
	return c // (a * b)

def sieveOfEratosthenes1(N, s):
	prime = [False] * (N + 1)
	for i in range(2, N + 1, 2):
		s[i] = 2
	for i in range(3, N + 1, 2):
		if prime[i] == False:
			s[i] = i
			for j in range(i, int(N / i) + 1, 2):
				if prime[i * j] == False:
					prime[i * j] = True
					s[i * j] = i

def generatePrimeFactors(N):
	s = [0] * (N + 1)
	sieveOfEratosthenes1(N, s)
	curr = s[N]
	cnt = 1
	factors = []
	power = []
	while N > 1:
		N //= s[N]
		if curr == s[N]:
			cnt += 1
			continue
		factors.append(curr)
		power.append(cnt)
		curr = s[N]
		cnt = 1
	return (factors, power)

def main():
	for _ in range(int(sin())):
		(n, m) = map(int, sin().split())
		arr = ain()
		s = sum(arr)
		if s > m:
			print(m)
		else:
			print(s)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin, stdout
import bisect

def ii():
	return int(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline()
for _ in range(ii()):
	(n, m) = mi()
	l1 = li()
	if sum(l1) >= m:
		print(m)
	else:
		print(sum(l1))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	c = sum(a)
	if k >= c:
		print(c)
	else:
		print(k)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math

def bin1(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = k ** mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin1(mid + 1, r, k, t, b, val, ans)
		else:
			return bin1(l, mid - 1, k, t, b, val, ans)

def bin2(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = t * k ** mid + b * mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin2(l, mid - 1, k, t, b, val, ans)
		else:
			return bin2(mid + 1, r, k, t, b, val, ans)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	l = []
	for i in range(2, n + 1):
		if prime[i]:
			l.append(i)
	return l

def bin(l, r, ll, val):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		if val >= ll[mid][0] and val <= ll[mid][1]:
			return mid
		elif val < ll[mid][0]:
			return bin(l, mid - 1, ll, val)
		else:
			return bin(mid + 1, r, ll, val)

def deci(n):
	s = ''
	while n != 0:
		if n % 2 == 0:
			n = n // 2
			s = '0' + s
		else:
			n = n // 2
			s = '1' + s
	return s

def diff(s1, s2):
	if len(s1) < len(s2):
		v = len(s1)
		while v != len(s2):
			s1 = '0' + s1
			v = v + 1
	else:
		v = len(s2)
		while v != len(s1):
			s2 = '0' + s2
			v = v + 1
	c = 0
	for i in range(len(s1)):
		if s1[i:i + 1] != s2[i:i + 1]:
			c = c + 1
	return c
from sys import stdin, stdout

def fac(a, b):
	v = a
	while a != b:
		v *= a - 1
		a = a - 1
	return v

def bino(l, r, n):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		val1 = math.log(n / mid + 1, 2)
		val2 = int(val1)
		if val1 == val2:
			return val1
		elif val1 < 1.0:
			return bino(l, mid - 1, n)
		else:
			return bino(mid + 1, r, n)

def binary(l, r, ll, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		if ll[mid] == val:
			return ll[mid]
		elif ll[mid] < val:
			ans = ll[mid]
			return binary(mid + 1, r, ll, val, ans)
		else:
			return binary(l, mid - 1, ll, val, ans)

def check(n):
	v = 1
	while n != 0:
		if n % 10 == 0 or n % 10 == 1:
			n = n // 10
		else:
			v = 0
			break
	return v
t = int(stdin.readline())
for i in range(t):
	(n, m) = map(int, input().split(' '))
	l = list(map(int, input().split(' ')))
	if m <= sum(l):
		print(m)
	else:
		print(sum(l))


t = int(input())
for k in range(t):
	temp = list()
	temp = input()
	temp = temp.split(' ')
	n = int(temp[0])
	m = int(temp[1])
	sum = 0
	a = [0] * n
	temp = input()
	temp = temp.split(' ')
	for i in range(n):
		a[i] = int(temp[i])
		sum = sum + a[i]
	while sum - m < 0:
		m = m - 1
	print(m)


import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	x = [int(n) for n in input().split()]
	print(min(sum(x), m))


import math
n = int(input())
for t in range(n):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if sum(b) >= a[1]:
		print(a[1])
	else:
		print(sum(b))


T = int(input())
for t in range(T):
	(students, maxScore) = [int(x) for x in input().split(' ')]
	scores = [int(x) for x in input().split(' ')]
	me = scores[0]
	total = sum(scores[1:])
	print(min(total + me, maxScore))


t = int(input())
f = ''
while t > 0:
	(n, m) = input().split()
	s = []
	s = input().split()
	sum = 0
	for i in range(1, int(n)):
		sum += int(s[i])
	ans = int(s[0]) + sum
	if ans > int(m):
		f = f + str(m) + '\n'
	else:
		f = f + str(ans) + '\n'
	t -= 1
print(f)


t = int(input())
for j in range(t):
	lst = [int(i) for i in input().split()]
	l = [int(i) for i in input().split()]
	avg = sum(l)
	if avg - lst[1] >= 0:
		print(lst[1])
	else:
		print(avg)


m = int(input())
l = []
for i in range(m):
	(t, max) = map(int, input().split())
	a = sum(list(map(int, input().split())))
	if max > a:
		l.append(a)
	else:
		l.append(max)
for i in l:
	print(i)


def highest(a, m):
	return m if sum(a) > m else sum(a)
for i in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(highest(b, a[1]))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	val = m
	sumarr = sum(arr) - arr[0]
	while True:
		if sumarr >= val - arr[0]:
			print(val)
			break
		else:
			val -= 1


from array import *
t = input()
for i in range(int(t)):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().strip().split()))[:n]
	sum1 = sum(arr)
	n1 = m - arr[0]
	if n1 <= sum1 - arr[0]:
		print(n1 + arr[0])
	else:
		print(sum1)


t = int(input())
for i in range(t):
	(n, k) = input().split(' ')
	n = int(n)
	k = int(k)
	lista = list(map(int, input().split(' ')))
	resultado = sum(lista)
	if resultado > k:
		print(k)
	else:
		print(resultado)


t = int(input())
for _ in range(t):
	args = [int(x) for x in input().split(' ')]
	n = args[0]
	m = args[1]
	a = [int(x) for x in input().split(' ')]
	if sum(a) >= m:
		print(m)
	else:
		print(sum(a))


INF = 10 ** 10

def main():
	(n, m) = get_list()
	li = get_list()
	my = sum(li)
	print(min(m, my))
import sys
from collections import defaultdict, Counter, deque
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
[main() for _ in range(int(input()))]
print(*out, sep='\n')


for __ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = m - a[0]
	d = sum(a[1:len(a)])
	if s <= d:
		print(m)
	else:
		print(a[0] + d)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	total = sum(a)
	diff = k - a[0]
	if sum(a[1:]) >= diff:
		ans = diff
	else:
		ans = sum(a[1:])
	print(a[0] + ans)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for i in range(t):
	(n, m) = invr()
	li = inlt()
	s = sum(li)
	print(min(s, m))


from sys import stdin

def main():
	input = lambda : stdin.readline()[:-1]
	T = int(input())
	for _ in [0] * T:
		(N, M) = map(int, input().split())
		A = map(int, input().split())
		print(min(sum(A), M))
main()


def solve(n, m, p):
	s = sum(p)
	print(min(s, m))

def main():
	inp = lambda : [int(x) for x in input().split()]
	tc = int(input())
	for _ in range(tc):
		(n, m) = inp()
		p = inp()
		solve(n, m, p)
main()


import math
t = int(input())
for _ in range(t):
	(n, m) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	ans = min(m, sum(arr))
	print(ans)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	lst = list(map(int, input().split()))
	new = sum(lst)
	if new >= m:
		print(m)
	else:
		print(new)


test = int(input())
for times in range(test):
	n_m = list(map(int, input().split()))
	max_score = n_m[1]
	scores = list(map(int, input().split()))
	total = sum(scores)
	if total >= max_score:
		result = max_score
	if total < max_score:
		result = total
	print(result)


for i in range(int(input())):
	(n, mm) = map(int, input().split())
	s = 0
	h = 0
	li = list(map(int, input().split()))
	for i in range(len(li)):
		s = s + li[i]
	if s == abs(s):
		h = 1
	s = s - li[0]
	m = mm - li[0]
	if h == 1:
		if m >= s:
			print(s + li[0])
		elif m < s:
			print(m + li[0])
		elif mm < li[0]:
			print(li[0])


for __ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	print(min(m, sum(arr)))


from pprint import pprint
q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	dat = list(map(int, input().split()))
	s = sum(dat)
	print(min(s, m))


import sys
import math
from collections import defaultdict, deque
import heapq
mod = 10 ** 9 + 7
t = int(sys.stdin.readline())
for _ in range(t):
	(n, m) = map(int, sys.stdin.readline().split())
	arr = list(map(int, sys.stdin.readline().split()))
	s = sum(arr)
	ans = min(m, s)
	print(ans)


import sys
t = int(input())
for _ in range(t):
	nm = input().split()
	n = int(nm.pop(0))
	m = int(nm.pop(0))
	a = [int(i) for i in input().split()]
	a = sum(a)
	print(min(m, a))


for i in range(int(input())):
	(n, m) = map(int, input().split())
	scores = list(map(int, input().split()))
	Sum = sum(scores) - scores[0]
	if Sum + scores[0] <= m:
		print(Sum + scores[0])
		continue
	elif Sum > m - scores[0]:
		print(m)
		continue


tc = int(input())
for kl in range(tc):
	a = input().split(' ')
	for o in range(len(a)):
		a[o] = int(a[o])
	b = input().split(' ')
	for lp in range(len(b)):
		b[lp] = int(b[lp])
	sdi = sum(b)
	print(min(sdi, a[1]))


t = int(input())
for g in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	x = max(l)
	l.remove(max(l))
	if sum(l) >= m - x:
		print(m)
	else:
		print(x + sum(l))


t = int(input())
for i in range(t):
	n_m = input()
	n_m = n_m.split(' ')
	n = int(n_m[0])
	m = int(n_m[1])
	array = input()
	array = array.split(' ')
	array = [int(x) for x in array]
	minhaNota = array[0]
	outros = sum(array[1:])
	nova = minhaNota + outros
	if nova > m:
		print(m)
	else:
		print(nova)


import collections
t = int(input())
while t > 0:
	z = 0
	(n, m) = map(int, input().split())
	ar = input()
	ar = ar.split()
	for i in ar:
		i = int(i)
		z += i
	print(min(int(m), z))
	t -= 1


for _ in range(int(input())):
	(students, full_mark) = map(int, input().split())
	marks = list(map(int, input().split()))
	for i in range(1, students):
		if marks[0] + marks[i] <= full_mark:
			marks[0] += marks[i]
		else:
			marks[0] += full_mark - marks[0]
	print(marks[0])


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	s = list(map(int, input().split()))
	print(min(y, sum(s)))


def solve():
	(n, m) = [int(x) for x in input().split(' ')]
	scores = [int(x) for x in input().split(' ')]
	maxi = scores[0]
	for j in range(1, n):
		maxi += scores[j]
		if maxi >= m:
			maxi = m
			break
	print(maxi)
t = int(input())
for i in range(t):
	solve()


def add_total(array):
	output = 0
	for i in range(len(array)):
		output += int(array[i])
	return output

def maximize_grade():
	cases = int(input())
	students = []
	grades = []
	for i in range(cases):
		students.append(input().split())
		grades.append(input().split())
	for i in range(len(students)):
		if int(students[i][1]) == int(grades[i][0]):
			print(int(grades[i][0]))
		else:
			total = add_total(grades[i])
			if total >= int(students[i][1]):
				print(int(students[i][1]))
			else:
				print(total)
maximize_grade()


def check(test, grades):
	if test[1] == grades[0]:
		return grades[0]
	added = sum(grades)
	if added >= test[1]:
		return test[1]
	else:
		return added
cases = int(input())
output = []
for i in range(cases):
	test = list(map(int, input().split()))
	grades = list(map(int, input().split()))
	output.append(check(test, grades))
for i in range(len(output)):
	print(output[i])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	print(min(k, sum(l)))


def sum(list):
	res = 0
	for i in list:
		res += i
	return res
t = int(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'
for l in range(0, t):
	(n, m) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	a1 = sum(a)
	res = min(a1, m)
	print(res)


q = int(input())
for i in range(q):
	w = input().split()
	(n, m) = w
	n = int(n)
	m = int(m)
	b = input().split()
	s = 0
	for j in range(len(b)):
		b[j] = int(b[j])
		s = s + b[j]
	if s > m:
		print(m)
	else:
		print(s)


from sys import stdin
T = int(input())
for _ in range(T):
	(n, m) = map(int, stdin.readline().split())
	scores = list(map(int, stdin.readline().split()))
	s = sum(scores[1:])
	minn = min(m - scores[0], s)
	print(scores[0] + minn)


t = int(input())
for itt in range(t):
	nm = list(map(int, input().strip().split()))[:2]
	a = list(map(int, input().strip().split()))[:nm[0]]
	sum = a[0]
	for i in range(1, nm[0], 1):
		sum += a[i]
	if sum > nm[1]:
		print(nm[1])
	else:
		print(sum)


for _ in range(int(input())):
	value = list(map(int, input().split()))
	student_count = value[0]
	max_score = value[1]
	score_list = map(int, input().split())
	sum = 0
	for i in score_list:
		sum = sum + i
	if max_score > sum:
		print(sum)
	else:
		print(max_score)


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	t = II()
	for _ in range(t):
		(n, m) = MI()
		aa = LI()
		print(min(sum(aa), m))
main()


for t in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	sm = sum(l[1:])
	x = l[0] + sm
	print(min(m, x))


a = int(input())
for j in range(0, a):
	b = input()
	c = input()
	d = b.split(' ')
	cantidad_alumnos = int(d[0])
	calificación_máxima = int(d[1])
	f = c.split(' ')
	g = []
	i = 1
	for h in f:
		h1 = int(h)
		g.append(h1)
	while g[0] < calificación_máxima and i < cantidad_alumnos:
		if g[i] > 0:
			g[i] = g[i] - 1
			g[0] = g[0] + 1
		else:
			i = i + 1
	print(g[0])


for i in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	sm = sum(arr)
	print(min(sm, m))


from functools import reduce
T = int(input())
for _ in range(T):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	lst = [int(i) for i in input().split()]
	su = reduce(lambda a, b: a + b, lst)
	while True:
		if su >= m:
			print(m)
			break
		else:
			m = m - 1


def go():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	return min(m, s)
t = int(input())
for _ in range(t):
	print(go())


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	x = sum(l)
	if k == x:
		print(x)
	elif k < x:
		print(k)
	elif k > x:
		print(x)


t = int(input())
for _ in range(t):
	(N, M) = map(int, input().split(' '))
	A = list(map(int, input().split(' ')))
	ans = A[0]
	i = 1
	while ans <= M:
		if i >= N:
			break
		ans += A[i]
		if ans <= M:
			i += 1
		else:
			ans = M
			break
	print(ans)


t = int(input())
for _ in range(t):
	(n_students, max_score) = [int(i) for i in input().split()]
	students = [int(i) for i in input().split()]
	print(min(sum(students), max_score))


for t in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if n == 1:
		print(a[0])
		continue
	i = 1
	while i < n and a[0] <= m:
		a[0] = a[0] + a[i]
		if a[0] >= m:
			a[0] = m
			break
		a[i] = 0
		i += 1
	print(a[0])


from collections import *
from sys import *
inp = stdin.readline
t = int(inp())
while t > 0:
	(n, m) = map(int, inp().split())
	nl = list(map(int, inp().split()))
	print(min(sum(nl), m))
	t -= 1


t = int(input())
for i in range(t):
	(n, m) = [int(x) for x in input().split()]
	sum = 0
	l = [int(i) for i in input().split()]
	for j in l:
		sum += j
	if sum < m:
		print(sum)
	else:
		print(m)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	len1 = len(a)
	for j in range(m, -1, -1):
		if j / len1 <= s / len1:
			print(j)
			break


def Bitplus():
	n = int(input())
	x = 0
	for i in range(n):
		a = input()
		if '+' in a:
			x += 1
		else:
			x -= 1
	print(x)

def GiftSetidk():
	n = int(input())
	for i in range(n):
		all = input().split(' ')
		x = int(all[0])
		y = int(all[1])
		a = int(all[2])
		b = int(all[3])
		counter = 0
		count = True
		while count:
			if x >= a and y >= b:
				x -= a
				y -= b
				counter += 1
			elif x >= b and y >= a:
				x -= b
				y -= a
				counter += 1
			else:
				count = False
		print(counter)

def Team():
	n = int(input())
	problemcount = 0
	for i in range(n):
		count = 0
		answer = input().split(' ')
		for i in range(len(answer)):
			answer[i] = int(answer[i])
		for i in answer:
			if i == 1:
				count += 1
		if count >= 2:
			problemcount += 1
	print(problemcount)

def NextRound():
	nk = input().split(' ')
	n = int(nk[0])
	k = int(nk[1])
	print(n, k)
	scores = input().split(' ')
	count = 0
	for i in range(n):
		scores[i] = int(scores[i])
	five = scores[k]
	for i in range(n):
		if scores[i] >= five and scores[i] > 0:
			count += 1
	print(count)

def Beautifulmatrix():
	steps = 0
	matrixes = []
	for i in range(5):
		i = [input().split(' ')]
		matrixes += i
	for i in range(5):
		for j in range(5):
			matrixes[i][j] = int(matrixes[i][j])
	for i in range(5):
		for j in range(5):
			if matrixes[i][j] > 0:
				x = j
				y = i
				break
	while x != 2 or y != 2:
		if x > 2:
			x -= 1
			steps += 1
		elif x < 2:
			x += 1
			steps += 1
		elif y > 2:
			y -= 1
			steps += 1
		elif y < 2:
			y += 1
			steps += 1
	print(steps)

def HelpfulMahts():
	s = input().split('+')
	s.sort()
	print('+'.join(s))

def WordCapitalization():
	word = input()
	List = []
	for i in word:
		List.append(i)
	List[0] = List[0].upper()
	s = ''
	for i in List:
		s += i
	print(s)

def Stonesonthetable():
	n = int(input())
	stones = []
	rrg = input()
	counter = 0
	for i in rrg:
		stones.append(i)
	for i in range(n - 1):
		if stones[i] == stones[i + 1]:
			counter += 1
	print(counter)

def BearandBigBrother():
	inpuut = input().split(' ')
	a = int(inpuut[0])
	b = int(inpuut[1])
	year = 0
	while a <= b:
		a *= 3
		b *= 2
		year += 1
	print(year)

def Wrongsubtraction():
	nk = input().split(' ')
	n = int(nk[0])
	k = int(nk[1])
	for i in range(k):
		p = str(n)
		if p[len(p) - 1] == '0':
			n //= 10
		else:
			n -= 1
	print(n)
import string

def Word():
	word = input()
	lower = 0
	upper = 0
	for i in word:
		if i in string.ascii_lowercase:
			lower += 1
		else:
			upper += 1
	if upper > lower:
		word = word.upper()
	else:
		word = word.lower()
	print(word)

def QueueattheSchool():
	nt = input().split(' ')
	n = nt[0]
	t = int(nt[1])
	a = input()
	b = []
	ref = ''
	for i in a:
		b.append(i)
	for k in range(t):
		whre = []
		for i in range(len(b) - 1):
			if b[i] == 'B' and b[i + 1] != 'B':
				whre.insert(0, i)
		for j in whre:
			b.pop(j)
			b.insert(j + 1, 'B')
	for i in b:
		ref += i
	print(ref)

def Nearlyluckynumber():
	n = input()
	if n.count('7') + n.count('4') == 7 or n.count('7') + n.count('4') == 4:
		print('YES')
	else:
		print('NO')

def Translation():
	s = input()
	t = input()
	n = []
	for i in t:
		n.insert(0, i)
	t = ''
	for i in n:
		t += i
	if t == s:
		print('YES')
	else:
		print('NO')

def ANTONandDanik():
	n = int(input())
	s = input()
	A = s.count('A')
	D = s.count('D')
	if A > D:
		print('Anton')
	elif D > A:
		print('Danik')
	else:
		print('Friendship')

def GeorgeandAccomodation():
	n = int(input())
	rooms = 0
	for i in range(n):
		pq = input().split(' ')
		p = int(pq[0])
		q = int(pq[1])
		if q - p >= 2:
			rooms += 1
	print(rooms)

def Magnets():
	n = int(input())
	Rows = []
	groups = 1
	for i in range(n):
		Rows += [input()]
	for i in range(n - 1):
		if Rows[i] != Rows[i + 1]:
			groups += 1
	print(groups)

def InSearcoanEasyProblem():
	n = int(input())
	counter = 0
	s = input().split(' ')
	if '1' in s:
		print('HARD')
	else:
		print('EASY')

def Hulk():
	c = int(input())
	i = 'I'
	s = ''
	it = 'it'
	for i in range(1, c + 1):
		if i == 1:
			s += 'hate '
		elif i % 2 == 0:
			s += 'that I love '
		else:
			s += 'that I hate '
	print(f'I {s}it')

def CalculatingFunctionidk():
	n = int(input())
	c = 0
	for i in range(1, n + 1):
		if i % 2 != 0:
			c -= i
		else:
			c += i
	print(c)

def IWannaBetheGuyidk():
	n = int(input())
	p = input().split(' ')
	q = input().split(' ')
	counter = 0
	for i in range(1, n + 1):
		if str(i) in p or str(i) in q:
			counter += 1
	if counter == n:
		print('I become the guy.')
	else:
		print('Oh, my keyboard!')

def horsesheo():
	n = input().split(' ')
	many = 4
	whatwas = []
	for i in range(len(n)):
		n[i] = int(n[i])
		if n[i] not in whatwas:
			whatwas.append(n[i])
	print(many - len(whatwas))

def ArrivaloftheGeneralidk():
	n = int(input())
	a = input().split(' ')
	max = 0
	minlist = []
	for i in range(n):
		a[i] = int(a[i])
	for i in a:
		if i > max:
			max = i
	maxloc = a.index(max)
	for i in a:
		minlist.insert(0, i)
	min = max
	for i in a:
		if i < min:
			min = i
	minloc = minlist.index(min)
	print(minloc + maxloc)

def UltraFastMathematician():
	first = input()
	second = input()
	s = ''
	for i in range(len(first)):
		if first[i] == '0' and second[i] == '1':
			s += '1'
		elif first[i] == '1' and second[i] == '0':
			s += '1'
		elif first[i] == '0' and second[i] == '0':
			s += '0'
		elif first[i] == '1' and second[i] == '1':
			s += '0'
	print(s)

def Insomniacure():
	klmn = []
	for i in range(4):
		klmn.append(int(input()))
	d = int(input())
	List = []
	if 1 in klmn:
		return d
	for i in range(4):
		mulit = klmn[i]
		while klmn[i] <= d:
			if klmn[i] not in List:
				List.append(klmn[i])
			klmn[i] += mulit
	return len(List)

def AntonandLetters():
	first = input()
	List = []
	for i in first:
		if i not in List and i in string.ascii_lowercase:
			List.append(i)
	print(len(List))

def Pangram():
	n = int(input())
	word = input().lower()
	List = []
	if n >= 26:
		for i in word:
			if i not in List:
				List.append(i)
		if len(List) == 26:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')

def Collectingcoons():
	n = int(input())
	for i in range(n):
		abcd = input().split(' ')
		for i in range(len(abcd)):
			abcd[i] = int(abcd[i])
		d = abcd[3]
		abcd.pop()
		maxi = 0
		for i in abcd:
			if i > maxi:
				maxi = i
		allindexes = [0, 1, 2]
		indexmax = abcd.index(maxi)
		allindexes.pop(indexmax)
		allminus = 0
		for i in allindexes:
			allminus += abcd[indexmax] - abcd[i]
		d -= allminus
		if d % 3 == 0 and d >= 0:
			print('YES')
		else:
			print('NO')

def Brainsphotos():
	nm = input().split(' ')
	colors = []
	for i in range(int(nm[0])):
		colors += input().split(' ')
	for i in colors:
		if i == 'C' or i == 'M' or i == 'Y':
			return '#Color'
	return '#Black&White'

def SerejaandDima():
	n = int(input())
	card = input().split(' ')
	S = 0
	D = 0
	sturn = True
	for i in range(n):
		if int(card[0]) > int(card[len(card) - 1]):
			if sturn:
				S += int(card[0])
				card.pop(0)
				sturn = False
			else:
				D += int(card[0])
				card.pop(0)
				sturn = True
		elif sturn:
			S += int(card[len(card) - 1])
			card.pop(len(card) - 1)
			sturn = False
		else:
			D += int(card[len(card) - 1])
			card.pop(len(card) - 1)
			sturn = True
	print(f'{S} {D}')

def Vanyaandcubes():
	n = int(input())
	counter = 1
	countdodo = 0
	rows = 0
	while n > 0:
		countdodo += counter
		counter += 1
		rows += 1
		n -= countdodo
	if n == 0:
		print(rows)
	else:
		print(rows - 1)

def GennadyandaCarGame():
	card = input()
	cards = input().replace(' ', '')
	for i in card:
		for j in cards:
			if i == j:
				return 'YES'
	return 'NO'

def FafaandhisCompany():
	n = int(input())
	ways = 0
	for i in range(1, n):
		a = n
		a -= i
		if a % i == 0:
			ways += 1
	print(ways)

def Mahmoudandehabandtheevenoddgame():
	n = int(input())
	Mahmoudsturn = True
	Mahmoudlsot = False
	Ehablost = False
	a = 0
	while not Mahmoudlsot and (not Ehablost):
		if Mahmoudsturn:
			if n % 2 == 0 and n >= 2:
				Ehablost = True
			elif n % 2 != 0 and n >= 2:
				a = n - 1
			else:
				Mahmoudlsot = True
		elif n % 2 == 1 and n >= 1:
			Mahmoudlsot = True
		elif n % 2 == 0 and n >= 1:
			a = n - 1
		else:
			Ehablost = False
		n -= a
		if Mahmoudsturn == True:
			Mahmoudsturn = False
		else:
			Mahmoudsturn = True
	if Mahmoudlsot == True:
		print('Ehab')
	else:
		print('Mahmoud')

def FloorNumber():
	t = int(input())
	for i in range(t):
		nx = input().split(' ')
		n = int(nx[0])
		x = int(nx[1])
		aparteements = 2
		floor = 1
		while n > aparteements:
			aparteements += x
			floor += 1
		print(floor)

def VustheCossackandaContest():
	nmk = input().split(' ')
	n = int(nmk[0])
	m = int(nmk[1])
	k = int(nmk[2])
	if n <= m and n <= k:
		print('Yes')
	else:
		print('No')

def NightattheMuseum():
	word = input()
	rotations = 0
	lower = string.ascii_lowercase + string.ascii_lowercase + string.ascii_lowercase
	loc = lower.index('a', 26, 2 * 26)
	for i in word:
		cplus = loc
		cminus = loc
		keep = True
		while keep:
			if i == lower[cplus] or i == lower[cminus]:
				keep = False
			else:
				cplus += 1
				cminus -= 1
				rotations += 1
				loc = lower.index(i, 26, 2 * 26)
	print(rotations)

def OrdinarYnumbers():
	n = int(input())
	for i in range(n):
		k = int(input())
		counter = 0
		for j in range(1, k + 1):
			a = str(j)
			if len(a) == a.count(a[0]):
				counter += 1
		print(counter)

def DieRoll():
	n = input().split(' ')
	y = int(n[0])
	w = int(n[1])
	number = 0
	dec = 6
	if y >= w:
		for i in range(y, 7):
			number += 1
	else:
		for i in range(w, 7):
			number += 1
	if number % 6 == 0:
		number = number // 6
		dec = 1
	elif number % 3 == 0:
		number = number // 3
		dec = 2
	elif number % 2 == 0:
		number = number // 2
		dec = 3
	print(f'{number}/{dec}')

def Borze():
	n = input()
	l = ''
	k = ''
	for i in n:
		if i == '.' and len(l) == 0:
			k += '0'
		else:
			l += i
			if len(l) == 2:
				if l == '-.':
					k += '1'
					l = ''
				else:
					k += '2'
					l = ''
	print(k)

def FairPlayoff():
	n = int(input())
	for i in range(n):
		loser = {}
		winner = {}
		count = 0
		k = input().split(' ')
		if int(k[0]) > int(k[1]):
			loser['one'] = int(k[1])
			winner['two'] = int(k[0])
		else:
			loser['one'] = int(k[0])
			winner['two'] = int(k[1])
		if int(k[2]) > int(k[3]):
			loser['two'] = int(k[3])
			winner['one'] = int(k[2])
		else:
			loser['two'] = int(k[2])
			winner['one'] = int(k[3])
		for i in loser:
			if loser[i] < winner[i]:
				count += 1
		if count >= 2:
			print('YES')
		else:
			print('NO')

def Bustoudaylanbd():
	n = int(input())
	s = []
	rem = -1
	first = True
	ss = ''
	for i in range(n):
		s += input().split('|')
	for i in range(len(s)):
		if s[i] == 'OO' and first:
			rem = i
			s[i] = '++'
			first = False
	for i in range(len(s)):
		if i % 2 == 0:
			ss += s[i] + '|'
		else:
			ss += s[i] + '\n'
	if not first:
		print('YES')
		print(ss)
	else:
		print('NO')

def Maximumincrease():
	n = int(input())
	arraa = input().split(' ')
	for i in range(len(arraa)):
		arraa[i] = int(arraa[i])
	counter = {}
	for i in range(n):
		counter[i] = 0
	count = 0
	last = 0
	for i in arraa:
		if i > last:
			last = i
			counter[count] += 1
		else:
			last = i
			count += 1
			counter[count] += 1
	max = 0
	for i in range(n):
		if counter[i] > max:
			max = counter[i]
	print(max)

def Jugglingletters():
	n = int(input())
	for i in range(n):
		k = int(input())
		s = ''
		map = {}
		possible = True
		for i in range(k):
			s += input()
		for i in s:
			if i not in map:
				map[i] = 1
			else:
				map[i] += 1
		for i in map:
			if map[i] % k != 0:
				possible = False
		if possible:
			print('YES')
		else:
			print('NO')

def Panoramixsprediction():
	nm = input().split(' ')
	n = int(nm[0])
	m = int(nm[1])
	first = True
	for i in range(n + 1, m):
		count = 0
		for j in range(2, i):
			if i % j == 0:
				count += 1
		if count == 0:
			first = False
			break
	if first:
		count = 0
		for j in range(2, m):
			if m % j == 0:
				count += 1
		if count == 0:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')

def ThreepilesofCanides():
	k = int(input())
	for i in range(k):
		n = input().split(' ')
		canides = 0
		for i in n:
			canides += int(i)
		if canides % 2 != 0:
			canides -= 1
		print(canides // 2)

def filename():
	n = int(input())
	name = input()
	more = 0
	map = {}
	map[more] = 0
	count = 0
	for i in name:
		if i == 'x':
			map[more] += 1
		elif map[more] != 0:
			more += 1
			map[more] = 0
	for i in map:
		if map[i] >= 3:
			while map[i] > 2:
				map[i] -= 1
				count += 1
	print(count)

def Football():
	map = {}
	current = 0
	s = input()
	f = s[0]
	map[current] = 0
	check = False
	for i in s:
		if i == f:
			map[current] += 1
		else:
			current += 1
			map[current] = 1
			f = i
	for i in map:
		if map[i] >= 7:
			check = True
	if check:
		print('YES')
	else:
		print('NO')

def CombinationLock1():
	n = int(input())
	fl = input()
	sl = input()
	count = 0
	for i in range(n):
		goup = int(fl[i])
		god = int(fl[i])
		cu = 0
		cd = 0
		keep = True
		while keep:
			if goup + 1 <= 9:
				goup += 1
				cu += 1
			else:
				goup = 0
				cu += 1
			if god - 1 >= 0:
				god -= 1
				cd += 1
			else:
				god = 9
				cd += 1
			if goup == int(sl[i]):
				count += cu
				keep = False
			elif god == int(sl[i]):
				count += cd
				keep = False
	print(count)

def Watermelon():
	n = int(input())
	down = n // 2
	up = n - down
	rge = up
	for i in range(rge):
		if up % 2 == 0 and down % 2 == 0:
			return print('YES')
		elif up + 1 < n and down - 1 > 0:
			up += 1
			down -= 1
		else:
			return print('NO')

def Dominopiling():
	nk = input().split(' ')
	n = int(nk[0])
	k = int(nk[1])
	mnk = n * k
	print(mnk // 2)

def yetanotherBookshelf():
	n = int(input())
	for i in range(n):
		le = int(input())
		K = input().split(' ')
		SK = []
		lili = []
		for i in range(le):
			if i + 1 <= le - 1:
				if K[i] == '1' and K[i + 1] == '1':
					lili.append(i)
		lili.reverse()
		for i in lili:
			K.pop(i)
		coun = 0
		while K.count('1') > 1:
			f = K.index('1')
			K.pop(f)
			K.insert(f + 1, '1')
			f += 1
			if K[f + 1] == '1':
				K.pop(f)
			coun += 1
		print(coun)

def Combinationlockittakestolong():
	n = int(input())
	fl = input()
	sl = input()
	counter = 0
	for i in range(n):
		up = int(fl[i])
		down = int(fl[i])
		while True:
			if up + 1 <= 9:
				up += 1
			else:
				up = 0
			if down - 1 >= 0:
				down -= 1
			else:
				down = 9
			counter += 1
			if up == int(sl) or down == int(sl):
				break

def iwannabetheguytolong():
	n = int(input())
	lvl = input().split(' ')
	lvls = input().split(' ')
	for i in range(1, n + 1):
		if str(i) not in lvl and str(i) not in lvls:
			return print('Oh, my keyboard!')
	return print('I become the guy.')

def giftsettolong():
	n = int(input())
	for i in range(n):
		rb = input().split(' ')
		x = int(rb[0])
		y = int(rb[1])
		a = int(rb[2])
		b = int(rb[3])
		giftset = 0
		while True:
			if x - a >= 0 and y - b >= 0:
				x -= a
				y -= b
				giftset += 1
			elif x - b >= 0 and y - a >= 0:
				x -= b
				y -= a
				giftset += 1
			else:
				break
		print(giftset)

def uniquwbidauctiontime():
	n = int(input())
	for i in range(n):
		k = int(input())
		list = input().split(' ')
		o = -1
		for i in range(k):
			if list.count(list[i]) == 1:
				if o == -1 or list[i] < o:
					o = list[i]
		if o != -1:
			print(list.index(o) + 1)
		else:
			print(o)

def equalizepriceagain():
	n = int(input())
	for i in range(n):
		k = int(input())
		numbers = input().split(' ')
		for i in range(len(numbers)):
			numbers[i] = int(numbers[i])
		total = 0
		for i in numbers:
			total += i
		if total % k == 0:
			print(total // k)
		else:
			while total % k != 0:
				total += 1
			print(total // k)

def shortsubstrings():
	n = int(input())
	for i in range(n):
		s = input()
		laist = []
		for i in range(len(s)):
			if i % 2 != 0 and i != len(s) - 1:
				laist.append(i)
		laist.reverse()
		s = list(s)
		for i in laist:
			s.pop(i)
		sa = ''
		for i in s:
			sa += i
		print(sa)

def policerecruits():
	n = int(input())
	k = input().split(' ')
	officers = 0
	crimes = 0
	for i in k:
		if int(i) == -1:
			if officers == 0:
				crimes += 1
			else:
				officers -= 1
		else:
			officers += int(i)
	print(crimes)

def thenewyear():
	xxx = input().split(' ')
	for i in range(len(xxx)):
		xxx[i] = int(xxx[i])
	xxx.sort()
	way = 0
	way += abs(int(xxx[1]) - int(xxx[0]))
	way += abs(int(xxx[1]) - int(xxx[2]))
	print(way)

def frogjumpingtimelimit():
	n = int(input())
	for i in range(n):
		abk = input().split(' ')
		a = int(abk[0])
		b = int(abk[1])
		k = int(abk[2])
		all = 0
		for i in range(k):
			if i % 2 == 0:
				all += a
			else:
				all -= b
		print(all)

def patrickandshopping():
	d = input().split(' ')
	d3 = 0
	for i in range(len(d)):
		if int(d[i]) > d3:
			d3 = int(d[i])
	d.pop(d.index(str(d3)))
	d1 = int(d[0])
	d2 = int(d[1])
	distance = d1 + d2
	if d3 <= distance:
		distance += d3
	else:
		distance += distance
	print(distance)

def Freeicecream():
	nx = input().split(' ')
	n = int(nx[0])
	ice = int(nx[1])
	diskid = 0
	for i in range(n):
		k = input().split(' ')
		if k[0] == '+':
			ice += int(k[1])
		elif ice >= int(k[1]):
			ice -= int(k[1])
		else:
			diskid += 1
	print(ice, diskid)

def Reviewsite():
	t = int(input())
	for i in range(t):
		n = int(input())
		upvotes = 0
		votes = input().split(' ')
		for i in votes:
			if i != '2':
				upvotes += 1
		print(upvotes)

def Lastyeasrtssubstring():
	t = int(input())
	for i in range(t):
		n = int(input())
		s = input()
		if s[0:4] == '2020' or s[n - 4:n] == '2020':
			print('YES')
		elif s[0:3] == '202' and s[n - 1] == '0':
			print('YES')
		elif s[n - 3:n] == '020' and s[0] == '2':
			print('YES')
		elif s[0:2] == '20' and s[n - 2] == '20':
			print('YES')
		elif s[n - 2:n] == '20' and s[0:2] == '20':
			print('YES')
		else:
			print('NO')

def Arena():
	t = int(input())
	for i in range(t):
		n = int(input())
		heros = input().split(' ')
		heorsint = [int(i) for i in heros]
		heorsint.sort()
		min = heorsint[0]
		winner = n - heorsint.count(min)
		print(winner)

def twoRabbitstoolongbutright():
	t = int(input())
	for i in range(t):
		xyab = input().split(' ')
		x = int(xyab[0])
		y = int(xyab[1])
		a = int(xyab[2])
		b = int(xyab[3])
		seconds = 0
		while x < y:
			x += a
			y -= b
			seconds += 1
		if x == y:
			print(seconds)
		else:
			print(-1)

def systemofequations():
	nm = input().split(' ')
	n = int(nm[0])
	m = int(nm[1])
	nm = [int(i) for i in nm]
	nm.sort()
	count = 0
	for i in range(nm[0] + 1):
		for j in range(nm[0] + 1):
			if i ** 2 + j == n and j ** 2 + i == m:
				count += 1
	print(count)

def polycarpwspockets():
	n = int(input())
	coins = input().split(' ')
	coins = [int(i) for i in coins]
	pocket = 0
	for i in coins:
		nmumbver = coins.count(i)
		if nmumbver > pocket:
			pocket = nmumbver
	print(pocket)

def repeaqtijgcipher():
	n = int(input())
	s = input()
	counter = 0
	rep = 1
	ns = ''
	while counter < n:
		counter += rep
		ns += s[counter - 1]
		rep += 1
	print(ns)

def Neaarestinterestingnumber():
	a = input()
	s = int(a)
	while True:
		if sum((int(i) for i in str(s))) % 4 == 0:
			return print(s)
		else:
			s += 1

def therearetwotzpesofburgers():
	t = int(input())
	for i in range(t):
		ess = input().split(' ')
		ess = [int(i) for i in ess]
		price = input().split(' ')
		buns = int(ess[0])
		totalmoney = 0
		first = True
		if int(price[0]) > int(price[1]):
			patties = ess[1]
			otherpatties = ess[2]
			money = int(price[0])
			othermoney = int(price[1])
		else:
			patties = ess[2]
			otherpatties = ess[1]
			money = int(price[1])
			othermoney = int(price[0])
		keep = True
		while keep:
			if buns - 2 >= 0 and patties - 1 >= 0:
				buns -= 2
				patties -= 1
				totalmoney += money
			elif buns - 2 >= 0 and patties == 0:
				if first:
					patties = otherpatties
					money = othermoney
					first = False
				else:
					print(totalmoney)
					keep = False
			else:
				print(totalmoney)
				keep = False

def threeswimmerstimelimitebutseemsright():
	t = int(input())
	for i in range(t):
		pabc = input().split(' ')
		pabc = [int(i) for i in pabc]
		a = 0
		b = 0
		c = 0
		p = pabc[0]
		keep = True
		while keep:
			if a < p:
				a += pabc[1]
			if b < p:
				b += pabc[2]
			if c < p:
				c += pabc[3]
			if a >= p and b >= p and (c >= p):
				list = [a - p, b - p, c - p]
				list.sort()
				print(list[0])
				keep = False

def Gregsworkout():
	n = int(input())
	training = input().split(' ')
	training = [int(i) for i in training]
	map = [0, 0, 0]
	current = 0
	for i in training:
		map[current] += i
		if current < 2:
			current += 1
		else:
			current = 0
	sorte = []
	for i in map:
		sorte.append(i)
	sorte.sort()
	index = map.index(sorte[2])
	if index == 0:
		print('chest')
	elif index == 1:
		print('biceps')
	else:
		print('back')

def heisttimelimitebutseemsright():
	n = int(input())
	all = input().split(' ')
	all = [int(i) for i in all]
	all.sort()
	counter = 0
	for i in range(all[0], all[len(all) - 1]):
		if i not in all:
			counter += 1
	print(counter)

def nonzero():
	t = int(input())
	for i in range(t):
		n = int(input())
		numbers = input().split(' ')
		count = numbers.count('0')
		for i in range(count):
			ind = numbers.index('0')
			numbers.pop(ind)
			numbers.insert(ind, '1')
		numbers = [int(i) for i in numbers]
		if sum(numbers) == 0:
			count += 1
		print(count)

def distinctdigits():
	lr = input().split(' ')
	for i in range(int(lr[0]), int(lr[1]) + 1):
		couynt = []
		for j in str(i):
			if j not in couynt:
				couynt.append(j)
		if len(couynt) == len(str(i)):
			return print(i)
	else:
		return print(-1)

def dawidandbagsofcandies():
	bags = input().split(' ')
	bags = [int(i) for i in bags]
	bags.sort()
	if bags[0] + bags[3] == bags[1] + bags[2]:
		print('YES')
	elif bags[3] == bags[0] + bags[1] + bags[2]:
		print('YES')
	else:
		print('NO')

def lastminuteenhancements():
	t = int(input())
	for i in range(t):
		n = int(input())
		notes = input().split(' ')
		lists = []
		for i in notes:
			if int(i) not in lists:
				lists.append(int(i))
			elif int(i) + 1 not in lists:
				lists.append(int(i) + 1)
		print(len(lists))

def Cakeminator():
	rc = input().split(' ')
	cake = []
	pices = 0
	rows = 0
	for i in range(int(rc[0])):
		cake.append([i for i in input()])
	for i in range(int(rc[1])):
		count = 0
		for j in range(int(rc[0])):
			if cake[j][i] == '.':
				count += 1
			if count == int(rc[0]):
				pices += count
				rows += 1
	for i in range(int(rc[0])):
		if 'S' not in cake[i]:
			pices += int(rc[1]) - rows
	print(pices)

def CME():
	t = int(input())
	for i in range(t):
		n = int(input())
		four = 4
		while four < n:
			four += 2
		print(four - n)

def FriendsandCandies():
	t = int(input())
	for i in range(t):
		n = int(input())
		cadies = input().split(' ')
		cadies = [int(i) for i in cadies]
		all = sum(cadies) % n
		count = 0
		if all != 0:
			print(-1)
		else:
			for i in cadies:
				if i > sum(cadies) // n:
					count += 1
			print(count)

def tworivalstudents():
	t = int(input())
	for i in range(t):
		nxab = input().split(' ')
		n = int(nxab[0])
		x = int(nxab[1])
		if int(nxab[2]) >= int(nxab[3]):
			bigger = int(nxab[2])
			smaller = int(nxab[3])
		else:
			bigger = int(nxab[3])
			smaller = int(nxab[2])
		for i in range(x):
			if bigger < n:
				bigger += 1
			elif smaller > 1:
				smaller -= 1
			else:
				break
		print(bigger - smaller)

def OmkarandPassword():
	t = int(input())
	for i in range(t):
		n = int(input())
		array = input().split(' ')
		array = [int(i) for i in array]
		pointer = 0
		while array.count(array[0]) != len(array):
			if array[pointer] != array[pointer + 1]:
				array.insert(pointer, array[pointer] + array[pointer + 1])
				array.pop(pointer)
				array.pop(pointer + 1)
			elif pointer + 1 < len(array) - 1:
				pointer += 1
			else:
				pointer = 0
		print(len(array))

def tanyaasndstairways():
	n = int(input())
	k = input().split(' ')
	k = [int(i) for i in k]
	last = []
	storeys = k.count(1)
	for i in range(n - 1):
		if k[i] >= k[i + 1]:
			last.append(k[i])
	last.append(k[n - 1])
	print(storeys)
	printable = ''
	for i in last:
		printable += str(i) + ' '
	print(printable)

def adjacentreplacements():
	t = int(input())
	wowowo = input()
	wo = wowowo.split(' ')
	wo = [int(i) for i in wo]
	for i in range(t):
		if wo[i] % 2 == 0:
			wo[i] -= 1
	s = ''
	for i in wo:
		s += str(i) + ' '
	print(s)

def Divideit():
	t = int(input())
	for i in range(t):
		n = int(input())
		counter = 0
		while n > 1:
			if n % 2 == 0:
				n = n // 2
				counter += 1
			elif n % 3 == 0:
				n = 2 * n // 3
				counter += 1
			elif n % 5 == 0:
				n = 4 * n // 5
				counter += 1
			else:
				counter = -1
				break
		print(counter)

def DiverseTeam():
	nk = input().split(' ')
	n = int(nk[0])
	k = int(nk[1])
	rating = input().split(' ')
	list = []
	s = ''
	for i in range(n):
		if rating[i] not in list:
			list.append(rating[i])
			s += str(i + 1) + ' '
		if len(list) == k:
			print('YES')
			return print(s)
	return print('NO')

def phoenixandgold():
	t = int(input())
	for i in range(t):
		nx = input().split(' ')
		n = int(nx[0])
		x = int(nx[1])
		gold = input().split(' ')
		gold = [int(i) for i in gold]
		count = 0
		s = ''
		if sum(gold) == x:
			print('NO')
		else:
			while len(gold) != 0:
				for i in range(len(gold)):
					if i < len(gold):
						if gold[i] + count != x:
							count += gold[i]
							s += str(gold[i]) + ' '
							gold.pop(i)
			print('YES')
			print(s)

def ingamechat():
	t = int(input())
	for i in range(t):
		n = int(input())
		s = input()
		c = 0
		for i in s:
			if i == ')':
				c += 1
			else:
				c = 0
		if c > n - c:
			print('Yes')
		else:
			print('No')

def IntegerSAequencedividing():
	list = [int(i) for i in range(1, int(input()) + 1)]
	list.reverse()
	A = 0
	B = 0
	while len(list) > 0:
		if len(list) != 1:
			one = list[0]
			two = list[1]
			list.pop(0)
			list.pop(0)
		else:
			one = list[0]
			list.pop(0)
			two = 0
		if abs(A + one - (B + two) <= abs(B + one - (A + two))):
			A += one
			B += two
		else:
			A += two
			B += one
	print(abs(A - B))

def shortestpathwithobstacle():
	t = int(input())
	for i in range(t):
		s = input()
		A = [int(i) for i in input().split(' ')]
		B = [int(i) for i in input().split(' ')]
		F = [int(i) for i in input().split(' ')]
		distance = abs(A[0] - B[0]) + abs(A[1] - B[1])
		if A[0] == B[0] and A[0] == F[0] and (min(A[1], B[1]) < F[1]) and (F[1] < max(A[1], B[1])) or (A[1] == B[1] and A[1] == F[1] and (min(A[0], B[0]) < F[0]) and (F[0] < max(A[0], B[0]))):
			distance += 2
		print(distance)

def Removeduplicates():
	t = int(input())
	numbers = input().split(' ')
	numbers.reverse()
	removed = []
	for i in numbers:
		if i not in removed:
			removed.append(i)
	removed.reverse()
	s = ''
	for i in removed:
		s += i + ' '
	print(len(removed))
	print(s)

def Threestrings():
	t = int(input())
	for i in range(t):
		a = input()
		b = input()
		c = input()
		work = True
		for i in range(len(a)):
			if a[i] != c[i] and b[i] != c[i]:
				work = False
		if work:
			print('YES')
		else:
			print('NO')

def specifictastesofandre():
	t = int(input())
	for i in range(t):
		li = [1 for i in range(int(input()))]
		s = ''
		for i in li:
			s += str(i) + ' '
		print(s)

def dejavu():
	t = int(input())
	for i in range(t):
		s = input()
		if s + 'a' == 'a' + s:
			print('NO')
		else:
			sl = list(s + 'a')
			rsl = []
			for i in sl:
				rsl.insert(0, i)
			if sl != rsl:
				print('YES')
				print(s + 'a')
			else:
				print('YES')
				print('a' + s)

def buythestring():
	t = int(input())
	for i in range(t):
		ncch = [int(i) for i in input().split(' ')]
		s = input()
		money = 0
		for i in s:
			if i == '0':
				money += min(ncch[1], ncch[2] + ncch[3])
			else:
				money += min(ncch[2], ncch[1] + ncch[3])
		print(money)

def Keyraces():
	svvtt = [int(i) for i in input().split(' ')]
	first = 2 * svvtt[3] + svvtt[0] * svvtt[1]
	scond = 2 * svvtt[4] + svvtt[0] * svvtt[2]
	if first > scond:
		print('Second')
	elif first < scond:
		print('First')
	else:
		print('Friendship')

def Angrystudents():
	t = int(input())
	for i in range(t):
		len = int(input())
		s = list(input())
		counter = 0
		counterlist = [0]
		if s.count('A') != 0:
			firstp = s.index('A')
			for i in range(firstp, len):
				if s[i] == 'P':
					counter += 1
				else:
					counterlist.append(counter)
					counter = 0
			counterlist.append(counter)
		print(max(counterlist))

def Frence():
	t = int(input())
	for i in range(t):
		d = sum([int(i) for i in input().split(' ')]) - 1
		print(d)

def playongwhithdice():
	ab = [int(i) for i in input().split(' ')]
	a = ab[0]
	b = ab[1]
	awins = 0
	draw = 0
	bwins = 0
	for i in range(1, 7):
		if abs(i - a) < abs(i - b):
			awins += 1
		elif abs(i - a) > abs(i - b):
			bwins += 1
		else:
			draw += 1
	print(awins, draw, bwins)

def arrayandpeaks():
	t = int(input())
	for i in range(t):
		(n, k) = [int(i) for i in input().split(' ')]
		listaa = [i for i in range(1, n - k + 1)]
		listoo = [i for i in range(n - k + 1, n + 1)]
		s = ''
		if len(listaa) > len(listoo):
			for i in range(len(listaa)):
				s += str(listaa[0]) + ' '
				listaa.pop(0)
				if len(listoo) != 0:
					s += str(listoo[0]) + ' '
					listoo.pop(0)
		else:
			s = '-1'
		print(s)

def mishkaandContest():
	(n, k) = [int(i) for i in input().split()]
	problems = [int(i) for i in input().split()]
	fp = 0
	sp = 0
	first = True
	for i in problems:
		if i <= k and first:
			fp += 1
		elif i > k and first:
			first = False
		elif i <= k and (not first):
			sp += 1
		else:
			sp = 0
	print(sp + fp)

def gotanygrapes():
	xyz = [int(i) for i in input().split(' ')]
	abc = [int(i) for i in input().split(' ')]
	c = 0
	for i in range(3):
		c += abc[i]
		c -= xyz[i]
		if c < 0:
			return print('NO')
	return print('YES')

def stringgenerations():
	t = int(input())
	ABC = ['a', 'b', 'c']
	for i in range(t):
		s = ''
		(n, k) = input().split(' ')
		for i in range(int(n)):
			s += ABC[i % 3]
		print(s)

def gradeallocation():
	t = int(input())
	for i in range(t):
		(n, m) = [int(i) for i in input().split(' ')]
		scores = [int(i) for i in input().split(' ')]
		summa = sum(scores)
		if summa >= m:
			print(m)
		else:
			print(summa)
gradeallocation()


def get_sum(scores, n):
	sum = 0
	for i in range(0, n):
		sum = sum + scores[i]
	return sum

def get_average(scores, n):
	return get_sum(scores, n) / n
t = int(input())
n = 0
m = 0
scores = []
for i in range(0, t):
	(n, m) = map(int, input().split())
	line = input().split(' ')
	scores = [int(i) for i in line]
	if get_sum(scores, n) >= m:
		max_score = m
	else:
		max_score = get_sum(scores, n)
	i = 1
	flag = 0
	while i < n:
		while scores[i] > 0 and scores[0] < max_score:
			scores[i] = scores[i] - 1
			scores[0] = scores[0] + 1
		i = i + 1
	print(scores[0])


for t in range(int(input())):
	(n, m) = map(int, input().split())
	v = map(int, input().split())
	print(min(m, sum(v)))


for i in range(int(input())):
	(a, b) = input().split()
	c = 0
	j = int(a)
	d = list(map(int, input().strip().split()))[:j]
	c = sum(d)
	print(min(c, int(b)))


from sys import stdin

def rl():
	return [int(w) for w in stdin.readline().split()]
test = int(stdin.readline())
while test > 0:
	(n, m) = rl()
	a = rl()
	x = 0
	tmp = 0
	for i in range(n):
		if i == 0:
			x = a[i]
		else:
			tmp = tmp + (a[i] - 0)
	print(min(x + tmp, m))
	test -= 1


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	sum1 = 0
	for j in range(len(a)):
		sum1 += a[j]
	if sum1 >= m:
		max1 = m
	else:
		max1 = sum1
	print(max1)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = [int(j) for j in input().split()]
	if sum(a) == m:
		print(m)
	if m < sum(a):
		print(m)
	if m > sum(a):
		print(sum(a))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	avg = sum(arr) / n
	remsum = sum(arr[1:])
	need = m - arr[0]
	if need >= remsum:
		print(remsum + arr[0])
	else:
		print(m)


import math
t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().split()))
	scores = list(map(int, input().split()))
	sum = 0
	for i in range(n):
		sum += scores[i]
	print(min(m, math.floor(sum)))


from functools import reduce
import os
import sys
from collections import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]
mo = 1000000007
for _ in range(inn()):
	(n, k) = value()
	a = arr()
	sm = sum(a[1:])
	print(min(k, sm + a[0]))


test = int(input())
for j in range(test):
	(n, m) = list(map(int, input().split(' ')))
	l = list(map(int, input().split(' ')))
	sum = 0
	for i in l:
		sum = sum + i
	avg = sum / len(l)
	if m / len(l) <= avg:
		print(m)
	else:
		print(sum)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	if sum(A) >= m:
		print(m)
	else:
		print(sum(A))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	arr = [int(k) for k in input().split()]
	s = sum(arr[:-1])
	m -= arr[-1]
	print(arr[-1] + (m if m <= s else s))


t = int(input())
for testcase in range(t):
	(n, m) = [int(x) for x in input().split()]
	array = [int(x) for x in input().split()]
	sum_of_array = sum(array)
	answer = min(sum_of_array, m)
	print(answer)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(n, m) = [int(i) for i in sys.stdin.readline().split()]
	a = [int(i) for i in sys.stdin.readline().split()]
	s = sum(a)
	print(min(s, m))


n = eval(input())
for test in range(n):
	ms = input()
	(s, m) = tuple([int(i) for i in ms.split()])
	mark = input()
	mark = [int(i) for i in mark.split()]
	total = sum(mark)
	if m < total:
		print(m)
	else:
		print(total)


inf = int(10000000000.0)
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	lis = list(map(int, input().split()))
	my = lis[0]
	other = sum(lis[1:])
	if m - my > other:
		print(my + other)
	else:
		print(m)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = [int(x) for x in input().split()]
	a = sum(l[1:])
	print(min(k, l[0] + a))


t = int(input())
for i in range(t):
	(n, m) = tuple(map(int, input().split()))
	a = list(map(int, input().split()))
	s = sum(a)
	print(min(m, s))


a = int(input())
x = int(0)
while x < a:
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	s = sum(c)
	if b[1] >= s:
		print(s)
	else:
		print(b[1])
	x = x + 1


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	ar = list(map(int, input().split()))
	for i in range(1, n):
		ar[0] += ar[i]
	print(min(ar[0], m))


result = ''
for i in range(0, int(input())):
	n = input()
	n = int(n.split()[1])
	string = input()
	l = list(map(int, string.split()))
	if sum(l) >= n:
		result += str(n) + '\n'
	else:
		result += str(sum(l)) + '\n'
print(result.rstrip('\n'))


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	others = sum(arr[1:])
	left = m - arr[0]
	print(arr[0] + min(left, others))


from sys import stdin

def func():
	return
for _ in range(int(stdin.readline())):
	(n, m) = map(int, stdin.readline().split())
	arr = list(map(int, stdin.readline().split()))
	ans = min(m, arr[0] + sum(arr[1:]))
	print(ans)


from sys import stdin, stdout, exit as sys_ret
(f_input, f_print, f_flush) = (stdin.readline, stdout.write, stdout.flush)
for _ in range(int(f_input())):
	(amount, maximum) = map(int, f_input().split())
	grades_sum = sum([int(__) for __ in f_input().split()])
	f_print(str(min(grades_sum, maximum)) + '\n')


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = [int(i) for i in input().split()]
	print(a[0] if n == 1 else min(m, sum(a)))


t = int(input())
for a in range(t):
	(n, m) = map(int, input().split())
	scores = list(map(int, input().split()))
	total = 0
	me = scores[0]
	for i in range(1, n):
		total += scores[i]
	if me + total >= m or me + total == m:
		print(m)
	else:
		print(me + total)


t = int(input())
for __ in range(t):
	(n, m) = [int(i) for i in input().split()]
	scores = [int(i) for i in input().split()]
	grade = sum(scores)
	if grade > m:
		grade = m
	print(grade)


t = int(input())
while t > 0:
	t -= 1
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	temp = sum(arr)
	if temp >= m:
		print(m)
	else:
		print(temp)


from statistics import mean
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	avg = mean(arr)
	bs = m / n
	if bs <= avg:
		print(m)
	else:
		print(round(m - n * (bs - avg)))


t = int(input().strip())
for testcase in range(t):
	(n, m) = map(int, input().strip().split())
	a = sum(map(int, input().strip().split()))
	print(min(a, m))


t = int(input())

def maxscore(n, m, l):
	x = 0
	for i in l:
		x += i
	if x > m:
		return m
	else:
		return x
for i in range(t):
	nm = input()
	nmlist = nm.split()
	n = int(nmlist[0])
	m = int(nmlist[1])
	l = input()
	lm = l.split()
	lis = []
	for i in lm:
		lis.append(int(i))
	print(maxscore(n, m, lis))


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	ls = list(map(int, input().split()))
	s = sum(ls)
	if s >= b:
		print(b)
	else:
		print(s)


n = int(input())
count = 0
d = {}
while count < n:
	s = input()
	s = s.split(' ')
	k = input()
	k = k.split(' ')
	d[str(count + 1)] = [s, k]
	count += 1
for b in d.values():
	maxi = int(b[0][-1])
	su = 0
	for x in b[1]:
		su += int(x)
	if maxi <= su:
		print(maxi)
	else:
		print(su)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	p = sum(map(int, input().split()))
	print(min(y, p))


tests = int(input())
for test in range(tests):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	if len(arr) == 1:
		print(arr[0])
	elif sum(arr[1:]) + arr[0] <= m:
		print(sum(arr[1:]) + arr[0])
	else:
		print(m)


c = int(input())
for i in range(c):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if sum(b) == a[1] or sum(b) > a[1]:
		print(a[1])
	elif sum(b) < a[1]:
		print(sum(b))


from math import ceil
n = int(input())
for i in range(n):
	(nbStud, maxNote) = map(int, input().split())
	notes = list(map(int, input().split()))
	print(min(maxNote, sum(notes)))


t = int(input())
for i in range(t):
	nums = input().split()
	n = int(nums[0])
	m = int(nums[1])
	scores = input().split()
	others_sum = 0
	other_scores = scores[1:]
	for s in other_scores:
		others_sum += int(s)
	if m - int(scores[0]) <= others_sum:
		print(m)
	else:
		print(int(scores[0]) + others_sum)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	scores = list(map(int, input().split()))
	sumof = sum(scores)
	print(min(sumof, m))


for i in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	z = l[0]
	sum1 = sum(l[1:])
	if l[0] < m:
		if sum1 + l[0] < m:
			print(sum1 + l[0])
		else:
			print(m)
	else:
		print(m)


def answer():
	n = int(input())
	while n:
		a = [int(x) for x in input().split()]
		b = [int(x) for x in input().split()]
		c = a[0]
		m = a[1]
		e = b[0]
		b.remove(e)
		for x in b:
			if x + e > m:
				e = m
				break
			else:
				e += x
		print(e)
		n -= 1
answer()


import math

def solve(m, n, data):
	maximum = sum(data)
	can_increase = min(maximum, m)
	return can_increase
samples = int(input())
for _ in range(samples):
	[n, m] = [int(i) for i in input().split(' ')]
	data = [int(i) for i in input().split(' ')]
	print(solve(m, n, data))


import os
import sys
from io import BytesIO, IOBase

def solution(arr, n, m):
	max_marks = sum(arr)
	if max_marks == 0:
		print(0)
		return
	if m > max_marks:
		print(max_marks)
		return
	print(m)

def main():
	t = int(input())
	for _ in range(t):
		(n, m) = [int(x) for x in input().split()]
		arr = [int(x) for x in input().split()]
		solution(arr, n, m)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


no_of_test_cases = int(input())
for i in range(0, 2 * no_of_test_cases, 2):
	(no_of_students, max_score) = input().split()
	list_marks = list(map(int, input().split()))
	average = sum(list_marks) / len(list_marks)
	if sum(list_marks) >= int(max_score):
		print(max_score)
	if sum(list_marks) < int(max_score):
		print(sum(list_marks))


def gradeAllot(stats, marks):
	(n, m) = (stats[0], stats[1])
	avg = sum(marks) / n
	if avg == 0:
		return 0
	elif sum(marks) >= m:
		return m
	return sum(marks)
tc = int(input())
for i in range(tc):
	st = list(map(int, input().split()))
	mks = list(map(int, input().split()))
	print(gradeAllot(st, mks))


def grd_alloc(arr, m):
	if len(arr) == 1:
		return arr[0]
	s = sum(arr[1:])
	if s >= m:
		return m
	else:
		k = arr[0] + s
		if k >= m:
			k = m
		return k
t = int(input())
for _ in range(t):
	nm = input().split()
	n = int(nm[0])
	m = int(nm[1])
	arr = list(map(int, input().split()))
	print(grd_alloc(arr, m))


t = int(input())
for _ in range(t):
	z = list(map(int, input().split()))
	(n, m) = (z[0], z[1])
	a = list(map(int, input().split()))
	sr = sum(a)
	if sr > m:
		print(m)
	else:
		print(sr)


import math
n = int(input())
for i in range(n):
	(n, m) = list(map(int, input().split()))
	sp = list(map(int, input().split()))
	sr = sum(sp) / len(sp)
	if sum(sp) >= m:
		print(m)
	else:
		print(sum(sp))


n = int(input())
Result = []
for i in range(0, n):
	List_Students_Higest = list(map(int, input().strip().split()))[0:2]
	len_ = List_Students_Higest[0]
	High = List_Students_Higest[1]
	List_Marks = list(map(int, input().strip().split()))[0:len_]
	if High <= sum(List_Marks):
		Result.append(High)
	else:
		Result.append(sum(List_Marks))
for i in Result:
	print(i)


T = int(input())
for t in range(T):
	(n, m) = [int(i) for i in input().split()]
	print(min(m, sum([int(i) for i in input().split()])))


t = int(input())
for T in range(t):
	(n, m) = list(map(int, input().split()))
	marks = list(map(int, input().split()))
	count = 0
	for i in range(1, n):
		count += marks[i]
	ans = marks[0]
	if ans + count > m:
		ans = m
	else:
		ans = ans + count
	print(ans)


numTestcases = int(input())
for i in range(numTestcases):
	l1 = list(map(int, input().split(' ')))
	m = l1[1]
	scores = list(map(int, input().split(' ')))
	print(min(m, sum(scores)))


t = int(input())
for i in range(t):
	(students, max_grade) = map(lambda x: int(x), input().split(' '))
	students_grades = sum(list(map(lambda x: int(x), input().split(' '))))
	print(min(max_grade, students_grades))


t = int(input().strip())
for _ in range(t):
	(n, m) = map(int, input().strip().split())
	lis = list(map(int, input().strip().split()))
	s = sum(lis)
	if len(lis) == 1:
		print(lis[0])
	elif s >= m:
		print(m)
	else:
		print(s)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
for _ in range(get_int()):
	(n, m) = get_int_list()
	lst = get_int_list()
	first = lst[0]
	s = sum(lst) - first
	diff = m - first
	if diff <= s:
		print(m)
	else:
		print(first + s)


tests = int(input())
for i in range(0, tests):
	(num, max) = (int(x) for x in input().split())
	grades = list(map(int, input().split()))
	if sum(grades) < max:
		print(sum(grades))
	else:
		print(max)


MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
from collections import *
for _ in range(ii()):
	(n, m) = f()
	a = il()
	print(min(sum(a), m))


T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	list1 = [int(x) for x in input().split()]
	sum = 0
	for i in range(len(list1)):
		if i != 0:
			sum += list1[i]
	newVar = m - list1[0]
	if sum >= newVar:
		print(m)
	else:
		print(list1[0] + sum)


for x in range(int(input())):
	(n, m) = list(map(int, input().split()))
	an = sum(map(int, input().split()))
	if an > m:
		print(m)
	elif an <= m:
		print(an)


import sys
read = sys.stdin.buffer.readline
for _ in range(int(read())):
	(n, m) = map(int, read().split())
	a = list(map(int, read().split()))
	print(min(sum(a), m))


t = int(input())
for a in range(t):
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	scores = input().split()
	total = 0
	for i in scores:
		total += int(i)
	for i in range(m, -1, -1):
		if total - i >= 0:
			print(i)
			break


n = int(input())
for i in range(n):
	(n, m) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	sum = 0
	for i in range(1, len(a)):
		sum = sum + a[i]
	b = m - a[0]
	if b <= sum:
		print(m)
	else:
		print(a[0] + sum)


def program():
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	print(min(m, sum(l)))
t = int(input())
for i in range(t):
	program()


def main():
	for _ in range(int(input())):
		(n, mx) = map(int, input().split(' '))
		l = list(map(int, input().split(' ')))
		sum_l = sum(l)
		if sum_l >= mx:
			print(mx)
		else:
			print(sum_l)
main()


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

def li():
	return list(map(int, sys.stdin.readline().split()))

def num():
	return map(int, sys.stdin.readline().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007

def solve():
	t = nu()
	for tt in range(t):
		(n, m) = num()
		a = li()
		x = m - a[0]
		ss = 0
		for i in range(1, n):
			ss += a[i]
		print(min(x, ss) + a[0])
solve()


t = int(input())
for case in range(t):
	(n, m) = [int(s) for s in input().split(' ')]
	a = [int(s) for s in input().split(' ')]
	print(min(m, sum(a)))


t = int(input())
for i in range(t):
	(n, m) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()][:n]
	total = sum(a)
	print(min(total, m))


t = int(input())
d = 0
for i in range(t):
	(n, m) = [int(x) for x in input().split()]
	s = list(map(int, input().split()))
	d = sum(s)
	if d > m:
		print(m)
	else:
		print(d)


T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	avg = 0
	for i in range(n):
		avg = avg + A[i]
	print(min(avg, m))


t = int(input())
while t > 0:
	arr = list(map(int, input().split()))
	n = arr[0]
	m = arr[1]
	a = list(map(int, input().split()))
	my_score = a.pop(0)
	a.sort(reverse=True)
	i = 0
	while my_score <= m and i <= n - 2:
		my_score += a[i]
		i += 1
	if my_score >= m:
		print(m)
	else:
		print(my_score)
	t = t - 1


def getMaximumScore(arr, m):
	total = sum(arr)
	first = arr[0]
	if first < m and total < m:
		return total
	elif first < m and total >= m:
		return m
	return first
test = int(input())
while test != 0:
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	arr = [int(x) for x in input().split()]
	print(getMaximumScore(arr, m))
	test -= 1


t = int(input())
for case in range(t):
	nm = [int(x) for x in input().split(' ')]
	n = nm[0]
	m = nm[1]
	a = [int(x) for x in input().split(' ')]
	score = min(sum(a), m)
	print(score)


t = int(input())

def calc(n, m):
	a = list(map(int, input().split()))
	for i in range(1, n):
		if a[0] < m:
			if a[0] + a[i] <= m:
				a[0] += a[i]
			else:
				return m
	return a[0]
answer = []
for i in range(t):
	(n, m) = map(int, input().split())
	answer.append(calc(n, m))
for item in answer:
	print(item)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	total = sum(a)
	avg = total / n
	my = m
	while True:
		if total - my >= 0:
			if (my + (total - my)) / n == avg:
				print(my)
				break
		else:
			my -= 1


A = []
q = int(input())

def avg():
	temp = 0
	for i in A:
		temp += i
	return temp
for i in range(q):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split(' ')[:n]))
	if avg() < m:
		print(avg())
	else:
		print(m)


tc = int(input())
for j in range(tc):
	(n, m) = map(int, input().split())
	sum = 0
	num = []
	num = list(map(int, input().split()))
	for i in range(n):
		sum += num[i]
	print(min(sum, m))


for i in range(0, int(input())):
	(no_of_students, highest_mark) = input().split(' ')
	marks_list = input().split()
	sum_marks = 0
	for each_mark in marks_list:
		sum_marks += int(each_mark)
	if int(highest_mark) > sum_marks:
		print(sum_marks)
	else:
		print(highest_mark)


for _ in ' ' * int(input()):
	(a, b) = map(int, input().split())
	k = list(map(int, input().split()))
	print(min(b, sum(k)))


for i in range(int(input())):
	(n, m) = map(int, input().split())
	List = list(map(int, input().split()))
	count = 0
	for t in List:
		if count + t > m:
			count += m - count
			break
		count += t
	print(count)


t = int(input())
q = 0
while q < t:
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	print(min(m, sum(a)))
	q += 1


case = int(input())
for i in range(case):
	(x, y) = [int(i) for i in input().split()]
	lis = list(map(int, input().split()))
	count = 0
	for i in lis:
		count += i
		if count >= y:
			break
	if count >= y:
		print('' + str(y))
	else:
		print('' + str(count))


t = int(input())
while t:
	l1 = [int(a) for a in input().split()]
	l2 = [int(b) for b in input().split()]
	s = sum(l2)
	if s - l1[1] >= 0:
		print(l1[1])
	else:
		print(s)
	t -= 1


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = [int(i) for i in input().split()]
	summ = sum(a) - a[0]
	aa = m - a[0]
	bb = min(aa, summ)
	print(a[0] + bb)


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	(n, m) = mints()
	s = sum(mints())
	print(min(s, m))
for i in range(mint()):
	solve()


t = int(input())
for i in range(t):
	s = input().split()
	k = int(s[1])
	su = 0
	s1 = input().split()
	for i in s1:
		su += int(i)
	if su >= k:
		print(k)
	else:
		print(su)


n = int(input())
for i in range(n):
	(x, y) = (int(x) for x in input().split())
	a = input()
	s = a.split(' ')
	sum = 0
	for j in s:
		sum = sum + int(j)
	if sum > y:
		print(y)
	else:
		print(sum)


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = int(input())
for tt in range(t):
	(n, m) = map(int, sys.stdin.readline().split(' '))
	a = list(map(int, sys.stdin.readline().split(' ')))
	s = sum(a) - a[0]
	print(min(m, a[0] + s))
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


t = int(input())
for i in range(t):
	(n, m) = [int(x) for x in input().split()]
	scores = [int(x) for x in input().split()]
	total = sum(scores)
	if total > m:
		print(m)
	else:
		print(total)


def ii():
	return int(input())

def mii():
	return map(int, input().split())

def lmii():
	return list(mii())

def main():
	for _ in range(ii()):
		(r, m) = mii()
		a = lmii()
		sam = 0
		for i in a:
			sam += i
		print(sam if m > sam else m)
main()


for _ in range(int(input())):
	(N, M) = map(int, input().split())
	List = [int(x) for x in input().split()]
	if List[0] + sum(List[1:]) >= M:
		Ans = M
	else:
		Ans = List[0] + sum(List[1:])
	print(Ans)


t = int(input())
while t > 0:
	lst = list(map(int, input().split()))
	score = list(map(int, input().split()))
	total_score = 0
	for i in range(lst[0]):
		total_score = total_score + score[i]
	if total_score > lst[1]:
		print(lst[1])
	else:
		print(total_score)
	t -= 1


t = int(input())
for i in range(t):
	entrada = list(map(int, input().split()))
	n = entrada[0]
	m = entrada[1]
	ai = list(map(int, input().split()))
	soma = sum(ai) - ai[0]
	if ai[0] + soma >= m:
		print(m)
	else:
		print(ai[0] + soma)


from sys import stdin, stdout
import bisect
import math

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
			n = n - 1
		else:
			a = a * a
			n = n >> 1
	return r

def solve():
	(n, m) = mp()
	l = li()
	pr(min(sum(l), m))
for _ in range(inp()):
	solve()


ntestcase = int(input())
while ntestcase > 0:
	(_, higherscore) = map(int, input().split())
	scores = list(map(int, input().split()))
	s = sum(scores[1:])
	if s + scores[0] > higherscore:
		print(higherscore)
	else:
		print(s + scores[0])
	ntestcase -= 1


def solve():
	(n, m) = map(int, input().split())
	tot = sum(list(map(int, input().split())))
	print(min(tot, m))
t = eval(input())
while t:
	solve()
	t -= 1


t = int(input())
for j in range(t):
	(n, highestGrade) = [int(i) for i in input().split()]
	grades = [int(i) for i in input().split()]
	maximum = highestGrade - grades[0]
	for i in range(1, n):
		if grades[i] < maximum:
			grades[0] += grades[i]
			maximum -= grades[i]
		else:
			grades[0] += maximum
			maximum -= grades[i]
			break
	print(grades[0])


t = int(input())

def solve(n, m, A):
	if n == 1:
		return A[0]
	s = sum(A[1:])
	res = min(A[0] + s, m)
	return res
for _ in range(t):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	print(solve(n, m, A))


for i in range(int(input())):
	(x, y) = map(int, input().split())
	l = list(map(int, input().split()))
	sumi = 0
	for j in range(x):
		sumi += l[j]
	if y >= sumi:
		print(sumi)
	else:
		print(y)


for test_c in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	c = 0
	a = list(map(int, input().split()))[:n]
	for i in range(n):
		c = c + a[i]
	if c <= m:
		print(c)
	else:
		print(m)


x = lambda : map(int, input().split())
for _ in range(int(input())):
	(n, m) = x()
	l = list(x())
	print(min(m, sum(l)))


def calc(m: int, scores: list):
	mySum: int = abs(sum(scores) - scores[0])
	if mySum >= m:
		return m
	elif mySum < m:
		tmp = scores[0] + mySum
		if tmp >= m:
			return m
		else:
			return tmp

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		scores: list = list(map(int, input().split()))
		print(calc(m, scores))
main()


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	if n == 1:
		print(l[0])
	else:
		a = l[0]
		s1 = sum(l[1:])
		if a + s1 > m:
			print(m)
		else:
			print(s1 + a)


t = int(input())
for i in range(t):
	s = input().split(' ')
	m = int(s[1])
	print(min(sum(list(map(int, input().split(' ')))), m))


for i in range(int(input())):
	a = [int(_) for _ in input().split()]
	b = [int(_) for _ in input().split()]
	if a[1] <= sum(b):
		print(a[1])
	else:
		print(sum(b))


t = int(input())
for i in range(t):
	d = [int(x) for x in input().split()]
	e = [int(x) for x in input().split()]
	print(min(d[1], sum(e)))


T = int(input())
a = list()
for i in range(T):
	st = input().split()
	N = int(st[0])
	M = int(st[1])
	eval = input().split()
	eval[0] = int(eval[0])
	o = 0
	while eval[0] < M and o + 2 <= len(eval):
		o += 1
		residue = M - eval[0]
		if residue > 0:
			if residue - int(eval[o]) > 0:
				eval[0] += int(eval[o])
			else:
				eval[0] += residue
	else:
		a.append(eval[0])
for i in a:
	print(i)


try:
	t = int(input())
	for i in range(0, t):
		w = []
		(n, m) = list(map(int, input().split(' ')))
		k = list(map(int, input().split(' ')))
		s = sum(k)
		if s >= m:
			print(m)
		elif s < m:
			print(s)
except:
	pass


for nt in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	x = s - l[0]
	print(min(s, m))


t = int(input())
while t:
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	if n == 1:
		print(l[0])
	else:
		print(min(sum(l), m))
	t -= 1


def f():
	(n, m) = [int(s) for s in input().split()]
	A = [int(s) for s in input().split()]
	s = 0
	for a in A:
		s += a
	if s > m:
		print(m)
		return
	print(s)
t = int(input())
for i in range(t):
	f()


for i in [0] * int(input()):
	(a, b) = map(int, input().split())
	c = eval(input().replace(' ', '+'))
	print(c if c < b else b)


for _ in range(int(input())):
	(n, m) = [int(__) for __ in input().split()]
	scores = [int(___) for ___ in input().split()]
	shit = sum(scores[1:])
	if shit < m - scores[0]:
		print(scores[0] + shit)
	else:
		print(m)


t = 1
t = int(input())
while t:
	t -= 1
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	max_ = sum(a)
	print(min(max_, m))


test_case = int(input())
for _ in range(test_case):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	mean = sum(a) / n
	for i in range(m, -1, -1):
		if i / n <= mean:
			print(i)
			break


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(n, m) = map(int, stdin.readline().split())
	arr = sum(list(map(int, stdin.readline().split())))
	print(min(arr, m))


import math
t = int(input())
ans = []
for i in range(t):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	a = input().split()
	s = 0
	for j in range(len(a)):
		a[j] = int(a[j])
		s = s + a[j]
	if s >= m:
		ans.append(m)
	else:
		ans.append(s)
for i in range(t):
	print(ans[i])


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n').split(' ')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	(n, m) = li()
	a = li()
	print(min(a[0] + sum((i for i in a[1:])), m))


import math
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	avg = sum(arr) / len(arr)
	if m <= sum(arr):
		print(m)
	else:
		print(sum(arr))


t_queries = int(input())
for query in range(t_queries):
	_input = [int(num) for num in input().split(' ')]
	num_students = _input[0]
	highest_possible_score = _input[1]
	scores = [int(num) for num in input().split(' ')]
	prev_average_score = sum(scores) / num_students
	ptr1 = num_students - 1
	if ptr1 > 0:
		while sum(scores) / num_students == prev_average_score and scores[0] < highest_possible_score and (ptr1 > 0):
			if scores[ptr1] == 0:
				ptr1 -= 1
			else:
				grade_to_add = highest_possible_score - scores[0]
				if scores[ptr1] >= grade_to_add:
					scores[0] += grade_to_add
					scores[ptr1] -= grade_to_add
				else:
					scores[0] += scores[ptr1]
					scores[ptr1] = 0
	print(scores[0])


t = int(input())
count = 0
exmass = []
while count < t:
	for i in range(t):
		(n, m) = map(int, input().split())
		ch = list(map(int, input().split()))
		massum = sum(ch)
		massr = massum / len(ch)
		fn = m
		if massum > m:
			exmass.append(m)
		else:
			exmass.append(massum)
		count += 1
for j in range(t):
	print(str(exmass[j]))


def main():
	t = int(input())
	for __ in range(t):
		(n, m) = map(int, input().split())
		a = list(map(int, input().split()))
		s = sum(a)
		if s >= m:
			print(m)
		else:
			print(s)
main()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(N, M) = map(int, input().split())
	X = list(map(int, input().split()))
	if N == 1:
		print(X[0])
		continue
	print(min(M, sum(X[1:]) + X[0]))


def solve():
	(n, m) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	k = sum(arr)
	print(min(m, k))
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	rest = arr[1:]
	dd = min(sum(rest), m - arr[0])
	print(arr[0] + dd)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	(*arr,) = map(int, input().split())
	ans = sum(arr)
	ans = min(ans, k)
	print(ans)


t = int(input())
output = []
for _ in range(t):
	(n, m) = [int(r) for r in input().split()]
	a = [int(r) for r in input().split()]
	output.append(min(m, sum(a)))
print('\n'.join((str(x) for x in output)))


(n,) = map(int, input().split())
for _ in range(n):
	(a, b) = map(int, input().split())
	s1 = sum(map(int, input().split()))
	print(min(s1, b))


for x in range(int(input())):
	(n, m) = map(int, input().strip().split()[:2])
	k = list(map(int, input().strip().split()[:n]))
	if sum(k) >= m:
		print(m)
	else:
		print(sum(k))


queries = int(input())
for _ in range(queries):
	(students, maxScore) = map(int, input().split())
	array = [int(value) for value in input().split()]
	available = sum(array[1:])
	current = array[0]
	if available > abs(current - maxScore):
		print(maxScore)
	else:
		print(current + available)


t = int(input())
for i in range(t):
	a = input()
	a = a.strip()
	a = a.split(' ')
	a = list(map(int, a))
	b = input()
	b = b.strip()
	b = b.split(' ')
	b = list(map(int, b))
	s = sum(b[1:])
	if s >= a[1] - b[0]:
		print(a[1])
	elif s < a[1] - b[0]:
		print(b[0] + s)


for t in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	ans = sum(arr) if sum(arr) < m else m
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	(n, m) = [int(x) for x in input().split(' ')]
	l = [int(x) for x in input().split(' ')]
	r = m - l[0]
	sum = 0
	flag = 0
	for i in range(1, n):
		sum += l[i]
		if sum >= r:
			flag = 1
			print(m)
			break
	if flag == 0:
		print(l[0] + sum)


from statistics import mean
for t in range(int(input())):
	(n, m) = map(int, input().split())
	a = [int(i) for i in input().split()]
	a_new = a.copy()
	startmean = mean(a)
	summ = sum(a[1:])
	a_last = a[1:].copy()
	a_last.sort()
	i = 1
	while a_new[0] <= m and i < n:
		if a_new[i] + a_new[0] > m:
			diff = m - a_new[0]
			a_new[0] += diff
			a_new[i] -= diff
			break
		else:
			a_new[0] += a_new[i]
			a_new[i] = 0
		i += 1
	print(a_new[0])


t = int(input())
for tt in range(t):
	(m, n) = map(int, input().split())
	li = list(map(int, input().split()))
	if sum(li) >= n:
		print(n)
	else:
		print(sum(li))


t = int(input())
s = []
for jnnj in range(0, t):
	x = input()
	xx = x.split()
	n = int(xx[0])
	m = int(xx[1])
	x = input()
	xx = x.split()
	p = int(xx[0])
	for i in range(1, n):
		p += int(xx[i])
	if p >= m:
		s.append(m)
	else:
		s.append(p)
for i in s:
	print(i)


q = int(input())
for _ in range(q):
	(n, m) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	sum1 = sum(arr)
	if sum1 > m:
		print(m)
	else:
		print(sum1)


import sys
import math

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]
t = read_int()
for i in range(t):
	(n, m) = read_int_line()
	a = read_int_line()
	print(min(m, sum(a)))


a = int(input())
for k in range(a):
	(b, c) = list(map(int, input().split()))
	d = list(map(int, input().split()))
	sum = 0
	for k in d:
		sum += k
	if sum >= c:
		print(c)
	else:
		print(sum)


t = int(input())
z = []
for i in range(0, t):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	a = list(map(int, input().strip().split()))[:n]
	av = sum(a) / n
	if sum(a) >= m:
		z.append(m)
	else:
		z.append(sum(a))
for i in z:
	print(i)


t = int(input())
while t != 0:
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	a = list(map(int, input().split()[:n]))
	b = sum(a)
	if b < m:
		print(b)
	else:
		print(m)
	t -= 1


import sys
import math
read = lambda : list(map(int, sys.stdin.readline().strip().split()))
for _ in range(int(input())):
	(m, n) = read()
	a = read()
	s = sum(a)
	print(min(s, n))


def main():
	(n, m) = map(int, input().split())
	add = 0
	a = list(map(int, input().split()))
	for i in range(1, n):
		add += a[i]
	print(min(m, a[0] + add))
	return

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


for i in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	x = sum(l)
	z = x / n
	y = 0
	for i in range(1, len(l)):
		y = y + l[i]
	if y + l[0] <= m:
		print(y + l[0])
	else:
		d = m - l[0]
		if d == 0:
			print(m)
		else:
			print(m)


num = int(input())
for _ in range(num):
	(n, max_point) = map(int, input().split())
	a = list(map(int, input().split()))
	print(min(sum(a), max_point))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	k = m - a[0]
	for i in range(1, len(a)):
		if a[i] >= k:
			a[i] -= k
			a[0] += k
			k = 0
		else:
			a[0] += a[i]
			k -= a[i]
			a[i] = 0
	print(a[0])


T = int(input())
for i in range(0, T):
	(n, m) = map(int, input().split(' '))
	A = list(map(int, input().split(' ')))
	if sum(A) >= m:
		print(m)
	else:
		print(sum(A))


t = input()
for _ in range(int(t)):
	(n, m) = map(int, input().split())
	a = input().split()
	ans = 0
	for i in range(n):
		ans += int(a[i])
	ans = min(ans, m)
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	(a, res) = (list(map(int, input().split())), 0)
	for x in a:
		res += x
	print(min(m, res))


import math
t = int(input())
for itt in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	higest = m
	ss = sum(arr)
	poss = min(higest, ss)
	kam = poss - arr[0]
	arr[0] = poss
	for i in range(1, len(arr)):
		mm = min(arr[i], kam)
		arr[i] -= mm
		kam -= mm
	print(arr[0])


import sys
t = int(input())
ans = []
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	new = sorted(arr, reverse=True)
	s = sum(new) - new[0]
	mi = new[0]
	mi = mi + min(k - mi, s)
	ans.append(str(mi))
print('\n'.join(ans))


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	if sum(arr) <= d:
		print(sum(arr))
	else:
		print(d)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	it = map(int, input().split())
	a = next(it)
	s = sum(it)
	print(a + min(m - a, s))


def solve():
	testCases = int(input().split()[0])
	for x in range(0, testCases):
		[n, m] = list(map(int, input().split()))
		scores = list(map(int, input().split()))
		average = sum(scores) / len(scores)
		myScore = scores[0]
		if m / len(scores) is average:
			print(m)
			continue
		for i in range(1, len(scores)):
			if myScore + scores[i] < m:
				myScore += scores[i]
				scores[i] = 0
			else:
				myScore = m
				break
		print(myScore)
solve()


from sys import stdin, stdout
rl = lambda : stdin.readline()
rll = lambda : stdin.readline().split()

def main():
	T = int(rl())
	for _ in range(T):
		(n, maxscore) = (int(x) for x in rll())
		A = [int(x) for x in rll()]
		allscores = sum((A[i] for i in range(len(A))))
		ans = min(maxscore, allscores)
		stdout.write(str(ans))
		stdout.write('\n')
	stdout.close()
main()


import sys
input = sys.stdin.readline
for _ in range(int(input().strip())):
	(n, m) = list(map(int, input().strip().split()))
	arr = list(map(int, input().strip().split()))
	f = arr[0]
	su = sum(arr[1:])
	print(min(f + su, m))


t = int(input())
for t0 in range(t):
	(n, m) = map(int, input().split())
	A = [int(j) for j in input().split()]
	summ = sum(A[1:])
	if summ >= m - A[0]:
		print(m)
	else:
		print(A[0] + summ)


t = int(input())
result = []
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	result.append(min(arr[0] + sum(arr[1:n]), m))
for x in result:
	print(x)


from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
for _ in range(iinput()):
	(n, m) = rinput()
	a = rlinput()
	print(min(m, sum(a)))


n = int(input())
for i in range(n):
	a = list(map(int, input().split()))
	num = a[0]
	max = a[1]
	xs = list(map(int, input().split()))
	if sum(xs) >= max:
		print(max)
	else:
		print(sum(xs))


n = int(input())
for p in range(n):
	ent = list(map(int, input().split(' ')))
	estudantes = ent[0]
	maxima = ent[1]
	notas = list(map(int, input().split(' ')))
	total = 0
	for i in range(estudantes):
		total += notas[i]
	if total >= maxima:
		print(maxima)
	else:
		print(int(total))


from sys import stdin
MAX = 1005

def line():
	return stdin.readline().strip()

def main():
	tc = int(line())
	for _ in range(tc):
		(n, m) = tuple(map(int, line().split()))
		ar = list(map(int, line().split()))
		first = ar[0]
		for item in ar[1:]:
			first += item
		print(min(first, m))
main()


def main():
	t = int(input())
	while t:
		t -= 1
		(n, m) = [int(x) for x in input().split()]
		a = [int(x) for x in input().split()]
		avg = sum(a)
		print(min(avg, m))
main()


for i in range(int(input())):
	(n, m) = map(int, input().split())
	l1 = list(map(int, input().split()))
	sum1 = 0
	for j in range(n):
		sum1 += l1[j]
	if sum1 >= m:
		print(m)
	else:
		print(sum1)


for i in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	a = list(map(int, input().split()))
	avg = sum(a) / n
	if sum(a) >= m:
		print(m)
	else:
		print(sum(a))


t = int(input())
for x in range(t):
	(n, m) = map(int, input().split())
	ls = list(map(int, input().split()))
	if sum(ls) < m:
		print(sum(ls))
	else:
		print(m)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	scores_array = tuple(map(int, input().split()))
	my_score = scores_array[0]
	for k in scores_array[1:]:
		my_score += k
		if my_score > m:
			print(m)
			break
	else:
		print(my_score)


t = int(input())
arr = list()
x = 1
for i in range(0, t):
	(n, m) = map(int, input().split())
	arr.append(list(map(int, input().split())))
	if sum(arr[i][1:]) + arr[i][0] >= m:
		print(m)
	else:
		print(arr[i][0] + sum(arr[i][1:]))


t = int(input())
for test in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = sum(arr[1:])
	print(min(m, arr[0] + s))


num_test_cases = int(input())
for i in range(num_test_cases):
	(num_students, max_score) = map(int, input().split())
	student_scores = list(map(int, input().split()))
	student_scores_sum = sum(student_scores)
	my_max_score = student_scores_sum if student_scores_sum <= max_score else max_score
	print(my_max_score)


for test in range(int(input())):
	(students, max_points) = list(map(int, input().split()))
	summe = sum(list(map(int, input().split())))
	i = 0
	while True:
		if summe - max_points + i >= 0:
			print(max_points - i)
			break
		i += 1


for _ in range(int(input())):
	(ignore_this_var, max_marks) = [int(h) for h in input().split(' ')]
	array_of_marks = [int(h) for h in input().split(' ')]
	sum_of_marks = sum(array_of_marks)
	ans = 0
	if sum_of_marks < max_marks:
		ans = sum_of_marks
	else:
		ans = max_marks
	print(ans)


print('\n'.join([str((lambda x, y: int(x >= y) * y + int(x < y) * x)(q[1][0] + sum(q[1][1:]), q[0][1])) for q in [[[int(w) for w in input().split()], [int(w) for w in input().split()]] for _ in range(int(input()))]]), end='')


t = int(input())
for _ in range(t):
	nm = list(map(int, input().split()))
	a = list(map(int, input().split()))
	n = nm[0]
	m = nm[1]
	som = sum(a)
	if som >= m:
		print(m)
		continue
	else:
		print(som)