#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

const int N = 3e3 + 5;

#define ll long long

void exgcd(int a, int b, int& x, int& y) {
	if (!b) {
		x = 1, y = 0;
	} else {
		exgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
}

int inv(int a, int n) {
	int x, y;
	exgcd(a, n, x, y);
	return (x < 0) ? (x + n) : (x);
}

const int Mod = 998244353;

template <const int Mod = :: Mod>
class Z {
	public:
		int v;

		Z() : v(0) {	}
		Z(int x) : v(x){	}
		Z(ll x) : v(x % Mod) {	}

		Z operator + (Z b) {
			int x;
			return Z(((x = v + b.v) >= Mod) ? (x - Mod) : (x));
		}
		Z operator - (Z b) {
			int x;
			return Z(((x = v - b.v) < 0) ? (x + Mod) : (x));
		}
		Z operator * (Z b) {
			return Z(v * 1ll * b.v);
		}
		Z operator ~() {
			return inv(v, Mod);
		}
		Z operator - () {
			return Z(0) - *this;
		}
		Z& operator += (Z b) {
			return *this = *this + b;
		}
		Z& operator -= (Z b) {
			return *this = *this - b;
		}
		Z& operator *= (Z b) {
			return *this = *this * b;
		}
};

Z<> qpow(Z<> a, int p) {
	Z<> rt = Z<>(1), pa = a;
	for ( ; p; p >>= 1, pa = pa * pa) {
		if (p & 1) {
			rt = rt * pa;
		}
	}
	return rt;
}

typedef Z<> Zi;

int n, m, C;
Zi ans[N];
int a[N], c[N];
Zi g[N][N], h[N];
Zi pw2[N], spw2[N], _spw2[N];

void dp1() {
	static Zi f[N][N];
	spw2[0] = 0, pw2[0] = 1;
	for (int i = 1; i <= n; i++)
		pw2[i] = pw2[i - 1] + pw2[i - 1];
	for (int i = 1; i <= n; i++)
		spw2[i] = spw2[i - 1] + spw2[i - 1] + 1;
	for (int i = 1; i <= n; i++)
		_spw2[i] = ~spw2[i];
	for (int l = 1; l <= n; l++) {
		memset(c, 0, (C + 1) << 2);
		int cnt = 0;
		Zi v = 1;
		for (int r = l; r <= n; r++) {
			int& cr = c[a[r]];
			if (!c[a[r]]) {
				cnt++, cr = 1;
			} else {
				cr++;
				v = v * _spw2[cr - 1] * spw2[cr];
			}
			if (cnt == C && a[l] != a[r]) {
				g[l][r] = v * _spw2[c[a[l]]] * pw2[c[a[l]] - 1] * _spw2[cr];
			} else if (cnt == C && l == r) {
				g[l][r] = 1;
			}
		}
		v = v * (cnt == C);
		h[l] = pw2[n - l + 1] - v;
	}
	/* for (int l = 1; l <= n; l++, cerr << '\n') {
		for (int r = 1; r <= n; r++) {
			cerr << g[l][r].v << ' ';
		}
	} */
	h[n + 1] = 1;
	/* for (int i = 1; i <= n; i++) {
		cerr << i << " " << h[i].v << '\n';
	} */
	for (int r = 1; r <= n; r++) {
		for (int l = 1; l <= r; l++) {
			g[l][r] += g[l - 1][r];
		}
	}
	f[0][0] = 1;
	for (int i = 0; i <= m; i++) {
		for (int j = 0; j <= n; j++) {
			Zi v = f[i][j];
			if (!v.v) {
				continue;
			}
			for (int r = j + 1; r <= n; r++) {
				f[i + 1][r] += v * (g[r][r] - g[j][r]);
			}
			ans[i] += v * h[j + 1];
		}
	}
}

void dp2() {
	int M = (m + 1) * (1 << C), S = (1 << C) - 1;
	Zi *fcur = new Zi[M];
	Zi *fnxt = new Zi[M];
	for (int i = 1; i <= n; i++) {
		a[i]--;
	}
	memset(fcur, 0, M << 2);
	fcur[0] = 1;
	for (int i = 1; i <= n; i++) {
		memset(fnxt, 0, M << 2);
		for (int j = 0; j <= m; j++) {
			for (int s = 0; s < S; s++) {
				Zi v = fcur[j << C | s];
				if (v.v) {
					fnxt[j << C | s] += v;
					if ((s | (1 << a[i])) < S) {
						fnxt[j << C | (s | (1 << a[i]))] += v;
					} else {
						fnxt[(j + 1) << C] += v;
					}
				}
			}
		}
		swap(fcur, fnxt);
	}
	for (int i = 0; i < M; i++) {
		ans[i >> C] += fcur[i];
	}
}

int main() {
	scanf("%d%d", &n, &C);
	m = n / C;
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
	}
	if (0 && C <= 20 && (1 << C) <= n) {
		dp2();
	} else {
		dp1();
	}
	ans[0] -= 1;
	for (int i = 0; i <= n; i++) {
		printf("%d ", ans[i].v);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int MOD = 998244353;
void add(int& a, int b) {
	a += b;
	if (a >= MOD) a -= MOD;
}
int mul(int a, int b) {
	return ll(a) * b % MOD;
}

int modinv(int a, int m = MOD) {
	return a == 1 ? a : m - modinv(m % a, a) * m / a;
}

const int MAXV = 4242;
int p2[MAXV], invp2[MAXV];
int p2m1[MAXV], invp2m1[MAXV];

void precomp() {
	p2[0] = 1;
	for (int i = 1; i < MAXV; i++) {
		p2[i] = mul(2, p2[i - 1]);
	}
	for (int i = 0; i < MAXV; i++) {
		invp2[i] = modinv(p2[i]);
	}

	for (int i = 0; i < MAXV; i++) {
		p2m1[i] = p2[i] - 1;
	}
	for (int i = 1; i < MAXV; i++) {
		invp2m1[i] = modinv(p2m1[i]);
	}
}

const int MAXN = 3010;
int N, C;
int A[MAXN];

int main() {
	precomp();

	scanf("%d %d", &N, &C);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]); A[i]--;
	}

	// TL is too tight right?
	vector<vector<int>> dp(N + 1);
	dp[0] = {{1}};
	if (C > 10) {
//	if (true) {
		for (int i = 0; i < N; i++) {
			vector<int> freq(C);
			int prod = 1;
			int cnt_bad = C - 1;
			for (int j = i; j >= 0; j--) {
				if (A[i] != A[j]) {
					if (!freq[A[j]]) {
						cnt_bad--;
					} else {
						prod = mul(prod, invp2m1[freq[A[j]]]);
					}
					freq[A[j]]++;
					prod = mul(prod, p2m1[freq[A[j]]]);
				}

				if (cnt_bad == 0) {
					if (dp[i + 1].size() < dp[j].size() + 1) {
						dp[i + 1].resize(dp[j].size() + 1);
					}
					for (int l = 0; l < int(dp[j].size()); l++) {
						add(dp[i + 1][l + 1], mul(prod, dp[j][l]));
					}
				}
			}
		}
	} else {
		vector<vector<int>> dp2(1 << C); // auxilary
		dp2[0] = {{1}};
		for (int i = 0; i < N; i++) {
			for (int m = (1 << C) - 1; m >= 0; m--) {
				if (dp2[m | (1 << A[i])].size() < dp2[m].size()) {
					dp2[m | (1 << A[i])].resize(dp2[m].size());
				}
				for (int l = 0; l < int(dp2[m].size()); l++) {
					add(dp2[m | (1 << A[i])][l], dp2[m][l]);
				}
			}

			swap(dp[i + 1], dp2[(1 << C) - 1]);
			dp[i + 1].insert(dp[i + 1].begin(), 0);
			if (dp2[0].size() < dp[i + 1].size()) {
				dp2[0].resize(dp[i + 1].size());
			}
			for (int l = 0; l < int(dp[i + 1].size()); l++) {
				add(dp2[0][l], dp[i + 1][l]);
			}
		}
	}

	vector<int> ans(N + 1);
	for (int i = 0; i <= N; i++) {
		for (int l = 0; l < int(dp[i].size()); l++) {
			add(ans[l], mul(p2[N - i], dp[i][l]));
		}
	}
	ans[0]--; // empty subarray
	for (int i = 0; i < N; i++) {
		add(ans[i], MOD - ans[i + 1]);
	}
	for (int i = 0; i <= N; i++) {
		printf("%d%c", ans[i], " \n"[i == N]);
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int MOD = 998244353;
void add(int& a, int b) {
	a += b;
	if (a >= MOD) a -= MOD;
}
int mul(int a, int b) {
	return ll(a) * b % MOD;
}

int modinv(int a, int m = MOD) {
	return a == 1 ? a : m - modinv(m % a, a) * ll(m) / a;
}

const int MAXV = 4242;
int p2[MAXV], invp2[MAXV];
int p2m1[MAXV], invp2m1[MAXV];

void precomp() {
	p2[0] = 1;
	for (int i = 1; i < MAXV; i++) {
		p2[i] = mul(2, p2[i - 1]);
	}
	for (int i = 0; i < MAXV; i++) {
		invp2[i] = modinv(p2[i]);
	}

	for (int i = 0; i < MAXV; i++) {
		p2m1[i] = p2[i] - 1;
	}
	for (int i = 1; i < MAXV; i++) {
		invp2m1[i] = modinv(p2m1[i]);
	}
}

const int MAXN = 3010;
int N, C;
int A[MAXN];

int main() {
	precomp();

	scanf("%d %d", &N, &C);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]); A[i]--;
	}

	// TL is too tight right?
	vector<vector<int>> dp(N + 1);
	dp[0] = {{1}};
	if (C > 10) {
//	if (true) {
		for (int i = 0; i < N; i++) {
			vector<int> freq(C);
			int prod = 1;
			int cnt_bad = C - 1;
			for (int j = i; j >= 0; j--) {
				if (A[i] != A[j]) {
					if (!freq[A[j]]) {
						cnt_bad--;
					} else {
						prod = mul(prod, invp2m1[freq[A[j]]]);
					}
					freq[A[j]]++;
					prod = mul(prod, p2m1[freq[A[j]]]);
				}

				if (cnt_bad == 0) {
					if (dp[i + 1].size() < dp[j].size() + 1) {
						dp[i + 1].resize(dp[j].size() + 1);
					}
					for (int l = 0; l < int(dp[j].size()); l++) {
						add(dp[i + 1][l + 1], mul(prod, dp[j][l]));
					}
				}
			}
		}
	} else {
		vector<vector<int>> dp2(1 << C); // auxilary
		dp2[0] = {{1}};
		for (int i = 0; i < N; i++) {
			for (int m = (1 << C) - 1; m >= 0; m--) {
				if (dp2[m | (1 << A[i])].size() < dp2[m].size()) {
					dp2[m | (1 << A[i])].resize(dp2[m].size());
				}
				for (int l = 0; l < int(dp2[m].size()); l++) {
					add(dp2[m | (1 << A[i])][l], dp2[m][l]);
				}
			}

			swap(dp[i + 1], dp2[(1 << C) - 1]);
			dp[i + 1].insert(dp[i + 1].begin(), 0);
			if (dp2[0].size() < dp[i + 1].size()) {
				dp2[0].resize(dp[i + 1].size());
			}
			for (int l = 0; l < int(dp[i + 1].size()); l++) {
				add(dp2[0][l], dp[i + 1][l]);
			}
		}
	}

	vector<int> ans(N + 1);
	for (int i = 0; i <= N; i++) {
		for (int l = 0; l < int(dp[i].size()); l++) {
			add(ans[l], mul(p2[N - i], dp[i][l]));
		}
	}
	ans[0]--; // empty subarray
	for (int i = 0; i < N; i++) {
		add(ans[i], MOD - ans[i + 1]);
	}
	for (int i = 0; i <= N; i++) {
		printf("%d%c", ans[i], " \n"[i == N]);
	}

	return 0;
}


#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
#define ll long long
#define mod 998244353
int dp1[2][3005][3005],dp[3005][3005],n,m,c,ans[3005],a[3005],vis[3005],f[3005][3005],mi[3005],sm[3005],now,sum[3005],inv[3005],h[3005][3005],num=1;
vector<int>vec[3005];
int add(int x){
	return x>=mod?x-mod:x;
}
int jian(int x){
	return x<0?x+mod:x;
}
void solve1(){
	dp1[now][0][0]=1;
	for(int i=0;i<n;i++){
		now^=1;
		memset(dp1[now],0,sizeof(dp1[now]));
		for(int t=0;t<=i/c;t++){
			for(int j=0;j<1<<c;j++){
				if(!dp1[now^1][t][j]) continue;
				int v=dp1[now^1][t][j];
				dp1[now][t][j]=add(dp1[now][t][j]+v);
				if((j|(1<<a[i+1]-1))==(1<<c)-1){
					dp1[now][t+1][0]=add(dp1[now][t+1][0]+v);
				}
				else{
					dp1[now][t][j|(1<<a[i+1]-1)]=add(dp1[now][t][j|(1<<a[i+1]-1)]+v);
				}
			}
		}
	}
	ans[0]=mod-1;
	for(int t=0;t<=n;t++){
		for(int j=0;j<1<<c;j++){
			ans[t]=add(ans[t]+dp1[now][t][j]);
		}
		printf("%d ",ans[t]);
	}
}
int ksm(int x,int y){
	int anss=1,t=x;
	while(y){
		if(y&1)anss=1ll*anss*t%mod;
		t=1ll*t*t%mod;
		y>>=1;
	}
	return anss;
}
void ins(int x){
	if(!vis[x]){
		vis[x]++;
		vis[0]--;
	}
	else{
		num=1ll*num*inv[vis[x]]%mod;
		vis[x]++;
		num=1ll*num*(mi[vis[x]]-1)%mod;
	}
}
void solve2(){
	for(int i=0;i<=n;i++) inv[i]=ksm(mi[i]-1,mod-2);
	for(int i=1;i<=n;i++){
		memset(vis,0,sizeof(vis));
		num=1;vis[0]=c;
		for(int t=i;t>=1;t--){
			ins(a[t]);
			if(vis[0]){
				f[t][i]=0;
				h[t][i]=mi[i-t];
			}
			else{
				int v=1ll*num*inv[vis[a[i]]]%mod;
				f[t][i]=v;
				h[t][i]=(mi[i-t]-1ll*v*mi[vis[a[i]]-1]%mod+mod)%mod;
			}
		}
	}
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		for(int t=0;t<m;t++){
			if(!dp[i][t]) continue;
			for(int j=i+1;j<=n;j++){
				dp[j][t+1]=(dp[j][t+1]+1ll*dp[i][t]*f[i+1][j])%mod;
			}
		}
	}
	for(int i=0;i<=n;i++){
		for(int t=i;t<=n;t++){
			sum[i]=(sum[i]+h[i][t])%mod;
		}
	}
	for(int i=0;i<=n;i++){
		for(int t=0;t<=m;t++){
			if(i>0) ans[t]=(ans[t]+dp[i][t])%mod;
			ans[t]=(ans[t]+1ll*dp[i][t]*sum[i+1])%mod;
		}
	}
	for(int i=0;i<=n;i++){
		printf("%d ",ans[i]);
	}
}
int main(){
	scanf("%d%d",&n,&c);
	m=n/c;
	mi[0]=1;
	for(int i=1;i<=n;i++) mi[i]=mi[i-1]*2%mod;
	int k=log2(n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	if(c<=k){
		solve1();
	}
	else{
		solve2();
	}
}


#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
#define ll long long
#define mod 998244353
int dp1[2][3005][3005],dp[3005][3005],n,m,c,ans[3005],a[3005],vis[3005],f[3005][3005],mi[3005],sm[3005],now,sum[3005],inv[3005],h[3005][3005],num=1;
vector<int>vec[3005];
int add(int x){
	return x>=mod?x-mod:x;
}
int jian(int x){
	return x<0?x+mod:x;
}
void solve1(){
	dp1[now][0][0]=1;
	for(int i=0;i<n;i++){
		now^=1;
		for(int t=0;t<=i/c;t++){
			for(int j=0;j<1<<c;j++){
				dp1[now][t][j]=0;
			}
		}
		for(int t=0;t<=i/c;t++){
			for(int j=0;j<1<<c;j++){
				if(!dp1[now^1][t][j]) continue;
				int v=dp1[now^1][t][j];
				dp1[now][t][j]=add(dp1[now][t][j]+v);
				if((j|(1<<a[i+1]-1))==(1<<c)-1){
					dp1[now][t+1][0]=add(dp1[now][t+1][0]+v);
				}
				else{
					dp1[now][t][j|(1<<a[i+1]-1)]=add(dp1[now][t][j|(1<<a[i+1]-1)]+v);
				}
			}
		}
	}
	ans[0]=mod-1;
	for(int t=0;t<=n;t++){
		for(int j=0;j<1<<c;j++){
			ans[t]=add(ans[t]+dp1[now][t][j]);
		}
		printf("%d ",ans[t]);
	}
}
int ksm(int x,int y){
	int anss=1,t=x;
	while(y){
		if(y&1)anss=1ll*anss*t%mod;
		t=1ll*t*t%mod;
		y>>=1;
	}
	return anss;
}
void ins(int x){
	if(!vis[x]){
		vis[x]++;
		vis[0]--;
	}
	else{
		num=1ll*num*inv[vis[x]]%mod;
		vis[x]++;
		num=1ll*num*(mi[vis[x]]-1)%mod;
	}
}
void solve2(){
	for(int i=0;i<=n;i++) inv[i]=ksm(mi[i]-1,mod-2);
	for(int i=1;i<=n;i++){
		memset(vis,0,sizeof(vis));
		num=1;vis[0]=c;
		for(int t=i;t>=1;t--){
			ins(a[t]);
			if(vis[0]){
				f[t][i]=0;
				h[t][i]=mi[i-t];
			}
			else{
				int v=1ll*num*inv[vis[a[i]]]%mod;
				f[t][i]=v;
				h[t][i]=(mi[i-t]-1ll*v*mi[vis[a[i]]-1]%mod+mod)%mod;
			}
		}
	}
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		for(int t=0;t<m;t++){
			if(!dp[i][t]) continue;
			for(int j=i+1;j<=n;j++){
				dp[j][t+1]=(dp[j][t+1]+1ll*dp[i][t]*f[i+1][j])%mod;
			}
		}
	}
	for(int i=0;i<=n;i++){
		for(int t=i;t<=n;t++){
			sum[i]=(sum[i]+h[i][t])%mod;
		}
	}
	for(int i=0;i<=n;i++){
		for(int t=0;t<=m;t++){
			if(i>0) ans[t]=(ans[t]+dp[i][t])%mod;
			ans[t]=(ans[t]+1ll*dp[i][t]*sum[i+1])%mod;
		}
	}
	for(int i=0;i<=n;i++){
		printf("%d ",ans[i]);
	}
}
int main(){
	scanf("%d%d",&n,&c);
	m=n/c;
	mi[0]=1;
	for(int i=1;i<=n;i++) mi[i]=mi[i-1]*2%mod;
	int k=log2(n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	if(c<=k){
		solve1();
	}
	else{
		solve2();
	}
}


#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
#define ll long long
#define mod 998244353
int dp1[2][3005][3005],dp[3005][3005],n,m,c,ans[3005],a[3005],vis[3005],f[3005][3005],mi[3005],sm[3005],now,sum[3005],inv[3005],h[3005][3005],num=1;
vector<int>vec[3005];
int add(int x){
	return x>=mod?x-mod:x;
}
int jian(int x){
	return x<0?x+mod:x;
}
void solve1(){
	dp1[now][0][0]=1;
	for(int i=0;i<n;i++){
		now^=1;
		memset(dp1[now],0,sizeof(dp1[now]));
		for(int t=0;t<=i/c;t++){
			for(int j=0;j<1<<c;j++){
				if(!dp1[now^1][t][j]) continue;
				int v=dp1[now^1][t][j];
				dp1[now][t][j]=add(dp1[now][t][j]+v);
				if((j|(1<<a[i+1]-1))==(1<<c)-1){
					dp1[now][t+1][0]=add(dp1[now][t+1][0]+v);
				}
				else{
					dp1[now][t][j|(1<<a[i+1]-1)]=add(dp1[now][t][j|(1<<a[i+1]-1)]+v);
				}
			}
		}
	}
	ans[0]=mod-1;
	for(int t=0;t<=n;t++){
		for(int j=0;j<1<<c;j++){
			ans[t]=add(ans[t]+dp1[now][t][j]);
		}
		printf("%d ",ans[t]);
	}
}
int ksm(int x,int y){
	int anss=1,t=x;
	while(y){
		if(y&1)anss=1ll*anss*t%mod;
		t=1ll*t*t%mod;
		y>>=1;
	}
	return anss;
}
void ins(int x){
	if(!vis[x]){
		vis[x]++;
		vis[0]--;
	}
	else{
		num=1ll*num*inv[vis[x]]%mod;
		vis[x]++;
		num=1ll*num*(mi[vis[x]]-1)%mod;
	}
}
void solve2(){
	for(int i=0;i<=n;i++) inv[i]=ksm(mi[i]-1,mod-2);
	for(int i=1;i<=n;i++){
		memset(vis,0,sizeof(vis));
		num=1;vis[0]=c;
		for(int t=i;t>=1;t--){
			ins(a[t]);
			if(vis[0]){
				f[t][i]=0;
				h[t][i]=mi[i-t];
			}
			else{
				int v=1ll*num*inv[vis[a[i]]]%mod;
				f[t][i]=v;
				h[t][i]=(mi[i-t]-1ll*v*mi[vis[a[i]]-1]%mod+mod)%mod;
			}
		}
	}
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		for(int t=0;t<m;t++){
			if(!dp[i][t]) continue;
			for(int j=i+1;j<=n;j++){
				dp[j][t+1]=(dp[j][t+1]+dp[i][t]*f[i+1][j])%mod;
			}
		}
	}
	for(int i=0;i<=n;i++){
		for(int t=i;t<=n;t++){
			sum[i]=(sum[i]+h[i][t])%mod;
		}
	}
	for(int i=0;i<=n;i++){
		for(int t=0;t<=m;t++){
			if(i>0) ans[t]=(ans[t]+dp[i][t])%mod;
			ans[t]=(ans[t]+dp[i][t]*sum[i+1])%mod;
		}
	}
	for(int i=0;i<=n;i++){
		printf("%d ",ans[i]);
	}
}
int main(){
	scanf("%d%d",&n,&c);
	m=n/c;
	mi[0]=1;
	for(int i=1;i<=n;i++) mi[i]=mi[i-1]*2%mod;
	int k=log2(n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	if(c<=k){
		solve1();
	}
	else{
		solve2();
	}
}


#include<bits/stdc++.h>
#define ll long long
#define uint unsigned
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
using namespace std;
const int mo=998244353;
const int N=3005;
int n,c,a[N];
void UPD(int &x,int y){
	(x+=y)>=mo?x-=mo:233;
}
namespace solver1{
	ll f[N][(1<<12)+5];
	void solve(){
		f[0][0]=1;
		int L=(1<<c)-1;
		int S=0,ST=0;
		For(i,1,n){
			int sta=1<<(a[i]-1);
			For(j,0,S) Rep(k,L,0) f[j][k|sta]+=f[j][k];
			For(j,0,S) f[j+1][0]+=f[j][L],f[j][L]=0;
			ST|=sta;
			if (ST==L) ST=0,S++;
			if (i%18==0||i==n)
				For(j,0,S) For(k,0,L) f[j][k]%=mo;
		}
		For(i,0,n/c){
			int ans=0;
			For(j,0,L) UPD(ans,f[i][j]);
			if (i==0) UPD(ans,mo-1);
			printf("%d ",ans);
		}
		For(i,n/c+1,n)
			printf("%d ",0);
	}
}
namespace solver2{
	int power(int x,int y){
		int s=1;
		for (;y;y/=2,x=1ll*x*x%mo)
			if (y&1) s=1ll*s*x%mo;
		return s;
	}
	int V[N],IV[N],tr2[N];
	int cnt[N],tr1[N][N];
	ll f[N][N];
	void solve(){
		For(i,0,n){
			V[i]=power(2,i)-1;
			IV[i]=power(V[i],mo-2);
		}
		For(i,1,n){
			For(j,1,c) cnt[j]=0;
			int GG=c,val=1;
			For(j,i,n){
				if (!cnt[a[j]]) --GG;
				else val=1ll*val*IV[cnt[a[j]]]%mo;
				tr1[i][j]=(GG?0:val);
				val=1ll*val*V[++cnt[a[j]]]%mo;
			}
			tr2[i]=power(2,n-i+1);
			UPD(tr2[i],mo-(GG?0:val));
		}
		f[0][0]=tr2[n+1]=1;
		For(i,0,n/c) For(j,i*c+c,n){
			ull tmp=0;
			For(k,i*c,j-c){
				tmp+=1ll*f[i][k]*tr1[k+1][j];
				if ((k&15)==15) tmp%=mo;
			}
			f[i+1][j]=tmp;
		}
		For(i,0,n/c){
			int ans=0;
			For(j,0,n) UPD(ans,1ll*f[i][j]*tr2[j+1]%mo);
			if (i==0) UPD(ans,mo-1);
			printf("%d ",ans);
		}
		For(i,n/c+1,n) printf("%d ",0);
	}
}
int main(){
	scanf("%d%d",&n,&c);
	For(i,1,n) scanf("%d",&a[i]);
	if (c<=11) solver1::solve();
	else solver2::solve();
}


#include<bits/stdc++.h>
#define ll long long
#define uint unsigned
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
using namespace std;
const int mo=998244353;
const int N=3005;
int n,c,a[N];
void UPD(int &x,int y){
	(x+=y)>=mo?x-=mo:233;
}
namespace solver1{
	int f[N][1<<12];
	void solve(){
		f[0][0]=1;
		int L=(1<<c)-1;
		For(i,1,n){
			int sta=1<<(a[i]-1),L1=(i-1)/c;
			For(j,0,L1) Rep(k,L,0) UPD(f[j][k|sta],f[j][k]);
			For(j,0,L1)	UPD(f[j+1][0],f[j][L]),f[j][L]=0;
		}
		For(i,0,n/c){
			int ans=0;
			For(j,0,L) UPD(ans,f[i][j]);
			if (i==0) UPD(ans,mo-1);
			printf("%d ",ans);
		}
		For(i,n/c+1,n)
			printf("%d ",0);
	}
}
namespace solver2{
	int power(int x,int y){
		int s=1;
		for (;y;y/=2,x=1ll*x*x%mo)
			if (y&1) s=1ll*s*x%mo;
		return s;
	}
	int V[N],IV[N];
	int cnt[N],tr1[N][N];
	int f[N][N],tr2[N];
	void solve(){
		For(i,0,n){
			V[i]=power(2,i)-1;
			IV[i]=power(V[i],mo-2);
		}
		For(i,1,n){
			For(j,1,c) cnt[j]=0;
			int GG=c,val=1;
			For(j,i,n){
				if (!cnt[a[j]]) --GG;
				else val=1ll*val*IV[cnt[a[j]]]%mo;
				tr1[i][j]=(GG?0:val);
				val=1ll*val*V[++cnt[a[j]]]%mo;
			}
			tr2[i]=power(2,n-i+1);
			UPD(tr2[i],mo-(GG?0:val));
		}
		f[0][0]=tr2[n+1]=1;
		For(i,1,n) For(j,0,(i-1)/c) if (f[j][i-1])
			For(k,i+c-1,n) UPD(f[j+1][k],1ll*f[j][i-1]*tr1[i][k]%mo);
		For(i,0,n/c){
			int ans=0;
			For(j,0,n) UPD(ans,1ll*f[i][j]*tr2[j+1]%mo);
			if (i==0) UPD(ans,mo-1);
			printf("%d ",ans);
		}
		For(i,n/c+1,n) printf("%d ",0);
	}
}
int main(){
	scanf("%d%d",&n,&c);
	For(i,1,n) scanf("%d",&a[i]);
	if (c<=12) solver1::solve();
	else solver2::solve();
}


#include<bits/stdc++.h>
#define ll long long
#define uint unsigned
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
using namespace std;
const int mo=998244353;
const int N=3005;
int n,c,a[N];
void UPD(int &x,int y){
	(x+=y)>=mo?x-=mo:233;
}
namespace solver1{
	int f[N][(1<<12)+5];
	void solve(){
		f[0][0]=1;
		int L=(1<<c)-1;
		int S=0,ST=0;
		For(i,1,n){
			int sta=1<<(a[i]-1);
			For(j,0,S) Rep(k,L,0) UPD(f[j][k|sta],f[j][k]);
			For(j,0,S)	UPD(f[j+1][0],f[j][L]),f[j][L]=0;
			ST|=sta;
			if (ST==L) ST=0,S++;
		}
		For(i,0,n/c){
			int ans=0;
			For(j,0,L) UPD(ans,f[i][j]);
			if (i==0) UPD(ans,mo-1);
			printf("%d ",ans);
		}
		For(i,n/c+1,n)
			printf("%d ",0);
	}
}
namespace solver2{
	int power(int x,int y){
		int s=1;
		for (;y;y/=2,x=1ll*x*x%mo)
			if (y&1) s=1ll*s*x%mo;
		return s;
	}
	int V[N],IV[N];
	int cnt[N],tr1[N][N];
	int f[N][N],tr2[N];
	void solve(){
		For(i,0,n){
			V[i]=power(2,i)-1;
			IV[i]=power(V[i],mo-2);
		}
		For(i,1,n){
			For(j,1,c) cnt[j]=0;
			int GG=c,val=1;
			For(j,i,n){
				if (!cnt[a[j]]) --GG;
				else val=1ll*val*IV[cnt[a[j]]]%mo;
				tr1[i][j]=(GG?0:val);
				val=1ll*val*V[++cnt[a[j]]]%mo;
			}
			tr2[i]=power(2,n-i+1);
			UPD(tr2[i],mo-(GG?0:val));
		}
		f[0][0]=tr2[n+1]=1;
		For(i,1,n) For(j,0,(i-1)/c) if (f[j][i-1])
			For(k,i+c-1,n) UPD(f[j+1][k],1ll*f[j][i-1]*tr1[i][k]%mo);
		For(i,0,n/c){
			int ans=0;
			For(j,0,n) UPD(ans,1ll*f[i][j]*tr2[j+1]%mo);
			if (i==0) UPD(ans,mo-1);
			printf("%d ",ans);
		}
		For(i,n/c+1,n) printf("%d ",0);
	}
}
int main(){
	scanf("%d%d",&n,&c);
	For(i,1,n) scanf("%d",&a[i]);
	if (c<=11) solver1::solve();
	else solver2::solve();
}


#include<bits/stdc++.h>
#define ll long long
#define uint unsigned
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
using namespace std;
const int mo=998244353;
const int N=3005;
int n,c,a[N];
void UPD(int &x,int y){
	(x+=y)>=mo?x-=mo:233;
}
namespace solver1{
	ll f[N][(1<<12)+5];
	void solve(){
		f[0][0]=1;
		int L=(1<<c)-1;
		int S=0,ST=0;
		For(i,1,n){
			int sta=1<<(a[i]-1);
			For(j,0,S) Rep(k,L,0) f[j][k|sta]+=f[j][k];
			For(j,0,S) f[j+1][0]+=f[j][L],f[j][L]=0;
			ST|=sta;
			if (ST==L) ST=0,S++;
			if (i%18==0||i==n)
				For(j,0,S) For(k,0,L) f[j][k]%=mo;
		}
		For(i,0,n/c){
			int ans=0;
			For(j,0,L) UPD(ans,f[i][j]);
			if (i==0) UPD(ans,mo-1);
			printf("%d ",ans);
		}
		For(i,n/c+1,n)
			printf("%d ",0);
	}
}
namespace solver2{
	int power(int x,int y){
		int s=1;
		for (;y;y/=2,x=1ll*x*x%mo)
			if (y&1) s=1ll*s*x%mo;
		return s;
	}
	int V[N],IV[N],tr2[N];
	int cnt[N],tr1[N][N];
	ll f[N][N];
	void solve(){
		For(i,0,n){
			V[i]=power(2,i)-1;
			IV[i]=power(V[i],mo-2);
		}
		For(i,1,n){
			For(j,1,c) cnt[j]=0;
			int GG=c,val=1;
			For(j,i,n){
				if (!cnt[a[j]]) --GG;
				else val=1ll*val*IV[cnt[a[j]]]%mo;
				tr1[i][j]=(GG?0:val);
				val=1ll*val*V[++cnt[a[j]]]%mo;
			}
			tr2[i]=power(2,n-i+1);
			UPD(tr2[i],mo-(GG?0:val));
		}
		f[0][0]=tr2[n+1]=1;
		For(i,0,n/c) For(j,i*c+c,n){
			ull tmp=0;
			For(k,i*c,j-c){
				tmp+=1ll*f[i][k]*tr1[k+1][j];
				if ((k&15)==15) tmp%=mo;
			}
			f[i+1][j]=tmp%mo;
		}
		For(i,0,n/c){
			int ans=0;
			For(j,0,n) UPD(ans,1ll*f[i][j]*tr2[j+1]%mo);
			if (i==0) UPD(ans,mo-1);
			printf("%d ",ans);
		}
		For(i,n/c+1,n) printf("%d ",0);
	}
}
int main(){
	scanf("%d%d",&n,&c);
	For(i,1,n) scanf("%d",&a[i]);
	if (c<=11) solver1::solve();
	else solver2::solve();
}


#include<bits/stdc++.h>
#define ll long long
#define uint unsigned
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
using namespace std;
const int mo=998244353;
const int N=3005;
int n,c,a[N];
void UPD(int &x,int y){
	(x+=y)>=mo?x-=mo:233;
}
namespace solver1{
	int f[N][(1<<12)+5];
	void solve(){
		f[0][0]=1;
		int L=(1<<c)-1;
		int S=0,ST=0;
		For(i,1,n){
			int sta=1<<(a[i]-1);
			For(j,0,S) Rep(k,L,0) UPD(f[j][k|sta],f[j][k]);
			For(j,0,S)	UPD(f[j+1][0],f[j][L]),f[j][L]=0;
			ST|=sta;
			if (ST==L) ST=0,S++;
		}
		For(i,0,n/c){
			int ans=0;
			For(j,0,L) UPD(ans,f[i][j]);
			if (i==0) UPD(ans,mo-1);
			printf("%d ",ans);
		}
		For(i,n/c+1,n)
			printf("%d ",0);
	}
}
namespace solver2{
	int power(int x,int y){
		int s=1;
		for (;y;y/=2,x=1ll*x*x%mo)
			if (y&1) s=1ll*s*x%mo;
		return s;
	}
	int V[N],IV[N];
	int cnt[N],tr1[N][N];
	int f[N][N],tr2[N];
	void solve(){
		For(i,0,n){
			V[i]=power(2,i)-1;
			IV[i]=power(V[i],mo-2);
		}
		For(i,1,n){
			For(j,1,c) cnt[j]=0;
			int GG=c,val=1;
			For(j,i,n){
				if (!cnt[a[j]]) --GG;
				else val=1ll*val*IV[cnt[a[j]]]%mo;
				tr1[i][j]=(GG?0:val);
				val=1ll*val*V[++cnt[a[j]]]%mo;
			}
			tr2[i]=power(2,n-i+1);
			UPD(tr2[i],mo-(GG?0:val));
		}
		f[0][0]=tr2[n+1]=1;
		For(i,1,n) For(j,0,(i-1)/c) if (f[j][i-1])
			For(k,i+c-1,n) UPD(f[j+1][k],1ll*f[j][i-1]*tr1[i][k]%mo);
		For(i,0,n/c){
			int ans=0;
			For(j,0,n) UPD(ans,1ll*f[i][j]*tr2[j+1]%mo);
			if (i==0) UPD(ans,mo-1);
			printf("%d ",ans);
		}
		For(i,n/c+1,n) printf("%d ",0);
	}
}
int main(){
	scanf("%d%d",&n,&c);
	For(i,1,n) scanf("%d",&a[i]);
	if (c<=12) solver1::solve();
	else solver2::solve();
}


#include<bits/stdc++.h>
using namespace std;
const int B=11;
const int maxn=3003;
const int mod=998244353;
int n,m,K;
int a[maxn],P[maxn],Inv[maxn];
int dp[maxn][maxn];
int f[maxn],cnt[maxn];
int g[maxn][1<<B|1];
inline int Pow(int a,int n){
	int ans=1;
	for(;n;n>>=1,a=a*1ll*a%mod)if(n&1)ans=ans*1ll*a%mod;
	return ans;
}
inline void Run_1(){
	int Lim=(1<<m)-1;
	g[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=K;j>=0;j--){
			dp[j+1][i]=g[j][Lim^(1<<a[i]-1)];
			for(int S=Lim-1;S>=0;S--){
				if((S|(1<<a[i]-1))==Lim)(g[j+1][0]+=g[j][S])%=mod;
				else (g[j][S|(1<<a[i]-1)]+=g[j][S])%=mod;
			}
		}
	}
}
int num[maxn][maxn];
inline void Run_2(){
	dp[0][0]=1;
	for(int r=1;r<=n;r++){
		memset(cnt,0,sizeof(int)*(m+3));
		++cnt[a[r]];
		int Bas=1,C=1;
		for(int l=r-1;l>=0;l--){
			if(C==m)num[l+1][r]=Bas;
			if(a[l]!=a[r]){
				C+=(!cnt[a[l]]);
				Bas=Bas*1ll*Inv[cnt[a[l]]]%mod*(P[++cnt[a[l]]]-1+mod)%mod;
			}
		}
	}
	static unsigned long long Inf=17e18;
	for(int i=1;i<=K;i++){
		for(int j=1;j<=n;j++){
			int Bas=1,C=1;
			unsigned long long tmp=0;
			for(int k=j-1;k>=0;k--)if(dp[i-1][k]&&num[k+1][j]){
				tmp+=dp[i-1][k]*1ll*num[k+1][j];
				if(tmp>Inf)tmp%=mod;
			}
			dp[i][j]=tmp%mod;
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);K=n/m;
	P[0]=Inv[0]=1;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]),P[i]=P[i-1]*2%mod;
		Inv[i]=Pow(P[i]-1+mod,mod-2);
	}
	if(m<=B)Run_1();
	else Run_2();
	for(int i=1;i<=K;i++)
		for(int j=1;j<=n;j++)
			(f[i]+=dp[i][j]*1ll*P[n-j]%mod)%=mod;
	f[0]=(P[n]-1+mod)%mod;
	for(int i=0;i<=n;i++)printf("%d ",(f[i]-f[i+1]+mod)%mod);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair

const int N = 1e5;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t, n, m, a[N];
	ll sum = 0;
	cin >> t;
	while(t--) {
		cin >> n >> m;
		for(int i=0; i<n; i++) {
			cin >> a[i];
			sum += a[i];
		}
		int ans = 0;
		for(int i=m; i>=0; i++) {
			if((sum-i)/3<=m*(n-1)) {
				ans = i;
				break;
			}
		}
		cout << ans << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair

const int N = 1e5;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t, n, m, a[N];
	ll sum;
	cin >> t;
	while(t--) {
		cin >> n >> m;
		sum = 0;
		for(int i=0; i<n; i++) {
			cin >> a[i];
			sum += a[i];
		}
		int ans = 0;
		for(int i=m; i>=0; i++) {
			if((sum-i)/3<=m*(n-1)) {
				ans = i;
				break;
			}
		}
		cout << ans << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair

const int N = 1e5;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t, n, m, a[N];
	ll sum;
	cin >> t;
	while(t--) {
		cin >> n >> m;
		sum = 0;
		for(int i=0; i<n; i++) {
			cin >> a[i];
			sum += a[i];
		}
		int ans = 0;
		for(int i=m; i>=0; i++) {
			if(sum-i>=0 && sum-i<=m*(n-1)) {
				ans = i;
				break;
			}
		}
		cout << ans << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair

const int N = 1e5;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t;
	ll n, m, s;
	cin >> t;
	while(t--) {
		cin >> n >> m;
		s = 0;
		for(int i=0; i<n; i++) {
			ll x;
			cin>>x;
			s=s+x;
		}
		cout << min(s,m) << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair

const int N = 1e5;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t, n, m, a[N];
	ll s;
	cin >> t;
	while(t--) {
		cin >> n >> m;
		s = 0;
		for(int i=0; i<n; i++) {
			ll x;
			cin>>x;
			s=s+x;
		}
		cout << min(s,m) << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair

const int N = 1e5;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t, n, m, a[N];
	ll s = 0;
	cin >> t;
	while(t--) {
		cin >> n >> m;
		for(int i=0; i<n; i++) {
			ll x;
			cin>>x;
			s=s+x;
		}
		cout << min(s,m) << '\n';
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t!=0)
    {
        t--;
        int n,m,i;
        cin>>n;
        int a[n];
        for(i=0; i<n; i++)
        {
            cin>>a[i];
        }
        for(i=0; i<n; i++)
        {
            if(a[i]==m)
            {
                a[i]=m;
                break;
            }
        }
        cout<<a[i]<<endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t!=0)
    {
        t--;
        int n,m,i;
        int a[n];
        cin>>n;
        for(i=0; i<n; i++)
        {
            cin>>a[i];
        }
        cin>>m;
        for(i=0; i<n; i++)
        {
            if(a[i]==m)
            {
                a[i]=m;
            }.
        }
        cout<<a[i]<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t!=0)
    {
        t--;
        int n,m,i;
        cin>>n;
        int a[n];
        for(i=0; i<n; i++)
        {
            cin>>a[i];
        }
        for(i=0; i<n; i++)
        {
            if(a[i]==m)
            {
                a[i]=m;
                break;
            }
        }
    }
    cout<<a[i]<<endl<<a[i];
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t!=0)
    {
        t--;
        int n,m,i;
        cin>>n;
        int a[n];
        for(i=0; i<n; i++)
        {
            cin>>a[i];
        }
        for(i=0; i<n; i++)
        {
            if(a[i]==m)
            {
                a[i]=m;
            }
        }
        cout<<a[i]<<endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t!=0)
    {
        t--;
        int n,m,i;
        cin>>n;
        cin>>m;
        int a[n];
        for(i=0; i<n; i++)
        {
            cin>>a[i];
        }
        for(i=0; i<n; i++)
        {
            if(a[i]!=m)
            {
                a[i]=m;
                break;
            }
        }
        cout<<a[i]<<endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t!=0)
    {
        t--;
        int n,m,i;
        cin>>n;
        int a[n];
        for(i=0; i<n; i++)
        {
            cin>>a[i];
        }
        for(i=0; i<n; i++)
        {
            if(a[i]==m)
            {
                a[i]=m;
                break;
            }
        }
        cout<<a[i]<<endl<<a[i];
    }
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long int n,m;
        cin>>n>>m;
        long int s=0;
        for(int i=1; i<=n; i++)
        {
            long int x;
            cin>>x;
            s+=x;
        }
        cout<<min(s,m)<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pi 2*acos(0.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ll long long
#define powof2(n) 1<<n
#define sumTillPowof2(n)  (1 << (n + 1)) - 1;

int main()
{

	// freopen("i.txt","r",stdin);
	// freopen("o.txt","w",stdout);
	int i,j,k,l,m,n,o,p,q=0;
	char x[100000],y[1000000];
	scanf("%d",&q);
	while(q--){
		scanf("%d %d",&n,&m);
		double avg=0;
		for(i=0;i<n;i++){scanf("%d",&p);
			avg+=p;}
		avg/=n;
		while(avg<m/n){
			m--;
			if(m<p){
				m==p;
				break;
			}
		}
		printf("%d\n",m );

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pi 2*acos(0.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ll long long
#define powof2(n) 1<<n
#define sumTillPowof2(n)  (1 << (n + 1)) - 1;

int main()
{

	// freopen("i.txt","r",stdin);
	// freopen("o.txt","w",stdout);
	int i,j,k,l,m,n,o,p,q=0;
	char x[100000],y[1000000];
	scanf("%d",&q);
	while(q--){
		scanf("%d %d",&n,&m);
		double avg=0;
		for(i=0;i<n;i++){scanf("%d",&p);
			avg+=p;}
		avg/=n;
		while(avg>m/n){
			m--;
		}
		printf("%d\n",m );

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pi 2*acos(0.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ll long long
#define powof2(n) 1<<n
#define sumTillPowof2(n)  (1 << (n + 1)) - 1;

int main()
{

	// freopen("i.txt","r",stdin);
	// freopen("o.txt","w",stdout);
	int i,j,k,l,m,n,o,p,q=0;
	char x[100000],y[1000000];
	scanf("%d",&q);
	while(q--){
		scanf("%d %d",&n,&m);
		double avg=0;
		for(i=0;i<n;i++){scanf("%d",&p);
			avg+=p;}
		avg/=n;
		while(avg<m/n){
			m--;
		}
		printf("%d\n",m );

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pi 2*acos(0.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ll long long
#define powof2(n) 1<<n
#define sumTillPowof2(n)  (1 << (n + 1)) - 1;

int main()
{

	//freopen("i.txt","r",stdin);
	//freopen("o.txt","w",stdout);
	int i,j,k,l,m,n,o,p,q=0;
	char x[100000],y[1000000];
	scanf("%d",&q);
	while(q--){
		scanf("%d %d",&n,&m);
		int avg=0;
		for(i=0;i<n;i++){scanf("%d",&p);
			avg+=p;}
		printf("%d\n",min(avg,m));
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pi 2*acos(0.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ll long long
#define powof2(n) 1<<n
#define sumTillPowof2(n)  (1 << (n + 1)) - 1;

int main()
{

	// freopen("i.txt","r",stdin);
	// freopen("o.txt","w",stdout);
	int i,j,k,l,m,n,o,p,q=0;
	char x[100000],y[1000000];
	scanf("%d",&q);
	while(q--){
		scanf("%d %d",&n,&m);
		double avg=0;
		for(i=0;i<n;i++){scanf("%d",&p);
			avg+=p;}
		avg/=n;

		float nf=0;
		nf+=m;
		int max=m;
	 while(avg<max/n){
	 	max--;
	 	if(max<p)max=p;
	 	}

		printf("%d\n",max);

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pi 2*acos(0.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ll long long
#define powof2(n) 1<<n
#define sumTillPowof2(n)  (1 << (n + 1)) - 1;

int main()
{

	// freopen("i.txt","r",stdin);
	// freopen("o.txt","w",stdout);
	int i,j,k,l,m,n,o,p,q=0;
	char x[100000],y[1000000];
	scanf("%d",&q);
	while(q--){
		scanf("%d %d",&n,&m);
		double avg=0;
		for(i=0;i<n;i++){scanf("%d",&p);
			avg+=p;}
		avg/=n;

		float nf=0;
		nf+=m;
		int max=m;
	 while(avg<nf/n)max--;

		printf("%d\n",max);

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pi 2*acos(0.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ll long long
#define powof2(n) 1<<n
#define sumTillPowof2(n)  (1 << (n + 1)) - 1;

int main()
{

	// freopen("i.txt","r",stdin);
	// freopen("o.txt","w",stdout);
	int i,j,k,l,m,n,o,p,q=0;
	char x[100000],y[1000000];
	scanf("%d",&q);
	while(q--){
		scanf("%d %d",&n,&m);
		double avg=0;
		for(i=0;i<n;i++){scanf("%d",&p);
			avg+=p;}
		avg/=n;

		printf("%d\n",m );

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pi 2*acos(0.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ll long long
#define powof2(n) 1<<n
#define sumTillPowof2(n)  (1 << (n + 1)) - 1;

int main()
{

	// freopen("i.txt","r",stdin);
	// freopen("o.txt","w",stdout);
	int i,j,k,l,m,n,o,p,q=0;
	char x[100000],y[1000000];
	scanf("%d",&q);
	while(q--){
		scanf("%d %d",&n,&m);
		double avg=0;
		for(i=0;i<n;i++){scanf("%d",&p);
			avg+=p;}
		avg/=n;

		float nf=0;
		nf+=m;
		int max=m;
	 while(avg<max/n){
	 	max--;
	 	}

		printf("%d\n",max);

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pi 2*acos(0.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ll long long
#define powof2(n) 1<<n
#define sumTillPowof2(n)  (1 << (n + 1)) - 1;

int main()
{

	// freopen("i.txt","r",stdin);
	// freopen("o.txt","w",stdout);
	int i,j,k,l,m,n,o,p,q=0;
	char x[100000],y[1000000];
	scanf("%d",&q);
	while(q--){
		scanf("%d %d",&n,&m);
		double avg=0;
		for(i=0;i<n;i++){scanf("%d",&p);
			avg+=p;}
		avg/=n;

		float nf=0;
		nf+=m;
		int max=m;

		while(avg!=nf/n){

			for(i=1;i<=m*(n-1);i++){

				nf+=i;

			if(avg==nf/n) break;
			nf-=i;

			}
			if(avg==nf/n) break;
			max--;
			nf=max;
			if(max<=p){
				max=p;
				break;
			}
		}
		printf("%d\n",max);

	}

	return 0;
}


// C++ program to demonstrate iterators
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#define rep(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        int a[n];
        int i;
        rep(i,n)
        {
            cin>>a[i];

        }
        if(n==1)
        {

            cout<<a[0]<<endl;
        continue;}

        i=1;
        while(a[0]<m)
        {
            if(a[i]==0)
                i++;
            a[0]++;
            a[i]--;
            if(i==5)
                break;
        }
        cout<<a[0]<<endl;

    }
}


// C++ program to demonstrate iterators
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#define rep(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        int a[n];
        int i;
        rep(i,n)
        {
            cin>>a[i];

        }
        if(n==1)
        {

            cout<<a[0]<<endl;
        return 0;}

        i=1;
        while(a[0]<m)
        {
            if(a[i]==0)
                i++;
            a[0]++;
            a[i]--;
            if(i==5)
                break;
        }
        cout<<a[0]<<endl;

    }
}


// C++ program to demonstrate iterators
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#define rep(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        int a[n];
        int i;
        rep(i,n)
        {
            cin>>a[i];

        }
        if(n==1)
        {

            cout<<a[0]<<endl;
        return 0;}

        i=1;
        while(a[0]<m)
        {
            if(a[i]==0)
                i++;
            a[0]++;
            a[i]--;
            if(i==5)
                break;
        }
        cout<<a[0]<<endl;

    }
}


// C++ program to demonstrate iterators
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#define rep(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        int a[n];
        int i;
        rep(i,n)
        {
            cin>>a[i];

        }

        i=1;
        while(a[0]<m)
        {
            if(a[i]<=0)
                i++;
            a[0]++;
            a[i]--;
            if(i==5)
                break;
        }
        cout<<a[0]<<endl;

    }
}


// C++ program to demonstrate iterators
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#define rep(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        int a[n];
        int i;
        rep(i,n)
        {
            cin>>a[i];

        }
        if(n==1)
        {

            cout<<a[0]<<endl;
        continue;}

        i=1;int f=0;
        while(a[0]<m)
        {

            while(a[i]==0)
            {
                i++;
                if(i==n)
                {
                    f=1;
                    break;
                }
            }
            if(f==1)
            {

                break;
            }
            a[0]++;
            a[i]--;
            if(i==n)
                break;
        }
        cout<<a[0]<<endl;

    }
}


// C++ program to demonstrate iterators
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#define rep(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        int a[n];
        int i;
        rep(i,n)
        {
            cin>>a[i];

        }
        if(n==1)
        {

            cout<<a[0]<<endl;
        continue;}

        i=1;int f=0;
        while(a[0]<m)
        {

            while(a[i]==0)
            {
                i++;
                if(i==n)
                {
                    break;f=1;
                }
            }
            if(f==1)
                break;
            a[0]++;
            a[i]--;
            if(i==n)
                break;
        }
        cout<<a[0]<<endl;

    }
}


// C++ program to demonstrate iterators
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#define rep(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        int a[n];
        int i;
        rep(i,n)
        {
            cin>>a[i];

        }

        i=1;
        while(a[0]<m)
        {
            if(a[i]<=0)
                i++;
            a[0]++;
            a[i]--;
            if(i==5)
                break;
        }
        cout<<a[0]<<endl;

    }
}


#include<bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main()
{
    long long int n,m,t,sum=0,temp;
    cin >> t;
    for(long long int i=0; i<t; i++)
    {
        cin >> n >> m;
        for(long long int i=0; i<n; i++)
        {
            cin >> temp;
            sum+=temp;
        }
        cout << min(m,sum) << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main()
{
    long long int n,m,t,sum=0,temp;
    cin >> t;
    for(long long int i=0; i<t; i++)
    {
        sum=0;
        cin >> n >> m;
        for(long long int i=0; i<n; i++)
        {
            cin >> temp;
            sum+=temp;
        }
        cout << min(m,sum) << endl;
    }
    return 0;
}


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


#include<bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main()
{
    long long int n,m,t,sum=0;
    cin >> t;
    while(t--)
    {
        cin >> n >> m;
        long long int a[n];
        for(long long int i=0; i<n; i++)
        {
            cin>>a[i];
            sum+=a[i];
        }
        cout << min(m,sum);
    }
    return 0;
}


#include<bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main()
{
    long long int n,m,t,sum=0;
    cin >> t;
    while(t--)
    {
        cin >> n >> m;
        long long int a[n];
        for(long long int i=0; i<n; i++)
        {
            cin>>a[i];
            sum+=a[i];
        }
        cout << min(m,sum) << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main()
{
    long long int n,m,t,sum=0,temp;
    cin >> t;
    for(ling long int i=0; i<t; i++)
    {
        cin >> n >> m;
        for(long long int i=0; i<n; i++)
        {
            cin >> temp;
            sum+=temp;
        }
        cout << min(m,sum) << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	int subTask;
	scanf("%d",&subTask);
	while(subTask){
		int maxV;
		int nvoti;
		scanf("%d %d",&nvoti,&maxV);
		int somma=0;
		for(int i=0;i<nvoti;i++){
			int tmp;
			scanf("%d",&tmp);
			somma+=tmp;
		}
		double media=somma/nvoti;

		printf("%d\n",maxV );
		--subTask;
	}

}


#include <bits/stdc++.h>

using namespace std;

int main(){
	long subTask;
	scanf("%ld",&subTask);
	while(subTask){
		long maxV;
		long nvoti;
		scanf("%ld %ld",&nvoti,&maxV);
		long somma=0;
		for(long i=0;i<nvoti;i++){
			long tmp;
			scanf("%ld",&tmp);
			somma+=tmp;
		}
		long double media=((long double)somma)/((long double)nvoti);

		printf("%ld\n",min(((long) (media*nvoti)) ,maxV) );
		--subTask;
	}

}


#include <bits/stdc++.h>

using namespace std;

int main(){
	long subTask;
	scanf("%ld",&subTask);
	while(subTask){
		long maxV;
		long nvoti;
		scanf("%ld %ld",&nvoti,&maxV);
		long somma=0;
		for(long i=0;i<nvoti;i++){
			long tmp;
			scanf("%ld",&tmp);
			somma+=tmp;
		}

		printf("%ld\n",min(somma ,maxV) );
		--subTask;
	}

}


#include <bits/stdc++.h>

using namespace std;

int main(){
	int subTask;
	scanf("%d",&subTask);
	while(subTask){
		int maxV;
		int nvoti;
		scanf("%d %d",&nvoti,&maxV);
		int somma=0;
		for(int i=0;i<nvoti;i++){
			int tmp;
			scanf("%d",&tmp);
			somma+=tmp;
		}
		double media=((double)somma)/((double)nvoti);

		printf("%d\n",min(((int) (media*nvoti)) ,maxV) );
		--subTask;
	}

}


#include <bits/stdc++.h>

using namespace std;

int main(){
	int subTask;
	scanf("%d",&subTask);
	while(subTask){
		int maxV;
		int nvoti;
		scanf("%d %d",&nvoti,&maxV);
		int somma=0;
		for(int i=0;i<nvoti;i++){
			int tmp;
			scanf("%d",&tmp);
			somma+=tmp;
		}
		double media=somma/nvoti;

		printf("%d\n",min(((int) media*nvoti) ,maxV) );
		--subTask;
	}

}


#include <bits/stdc++.h>

using namespace std;

int main(){
	int subTask;
	scanf("%d",&subTask);
	while(subTask){
		int maxV;
		int nvoti;
		scanf("%d %d",&nvoti,&maxV);
		int somma;
		for(int i=0;i<nvoti;i++){
			int tmp;
			scanf("%d",&tmp);
			somma+=tmp;
		}
		double media=somma/nvoti;

		printf("%d\n",min(((int) media*nvoti) ,maxV) );
		--subTask;
	}

}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int a, b, c, d;
  cin >> a;
  while (cin >> a >> b) {
    d = 0;
    while (a--) {
      cin >> c;
      d += c;
    }
    cout << (b > d ? d : b) << '\n';
  }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int a, b, c, d;
  cin >> a;
  while (cin >> a >> b) {
    d = 0;
    while (a--) {
      cin >> c;
      d += c;
      if (d >= b) {
        d = b;
        cin.ignore('\n');
        break;
      }
    }
    cout << d << '\n';
  }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int a, b;
  cin >> a;
  while (cin >> a >> b) {
    cout << b << '\n';
    while (a--) cin >> b;
  }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int a, b, c;
  cin >> a;
  while (cin >> a >> b >> c) {
    cout << (a > 1 ? b : c) << '\n';
    while (--a) cin >> b;
  }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int a, b, c, d;
  cin >> a;
  while (cin >> a >> b) {
    d = 0;
    while (a--) {
      cin >> c;
      d += c;
      if (d >= b) {
        d = b;
        cin.ignore(a * 2);
        break;
      }
    }
    cout << d << '\n';
  }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int64_t a, b, c, d;
  cin >> a;
  while (cin >> a >> b) {
    d = 0;
    while (a--) {
      cin >> c;
      d += c;
      if (d >= b) {
        d = b;
        cin.ignore(a * 2);
        break;
      }
    }
    cout << d << '\n';
  }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int a, b;
  cin >> a;
  while (cin >> a >> b) {
    cout << (a > 1 ? b : 0) << '\n';
    while (a--) cin >> b;
  }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int64_t a, b, c, d;
  cin >> a;
  while (cin >> a >> b) {
    d = 0;
    while (a--) {
      cin >> c;
      d += c;
      if (d > b) {
        d = b;
        cin.ignore(a * 2);
        break;
      }
    }
    cout << d << '\n';
  }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int a, b, c, d;
  cin >> a;
  while (cin >> a >> b) {
    d = 0;
    while (a--) {
      cin >> c;
      d += c;
      if (d >= b) {
        d = b;
        cin.ignore(a * 2);
        break;
      }
    }
    cout << (b > d ? d : b) << '\n';
  }
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    long long int  t,k,m,sum=0;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int n,m;
        cin>>n>>m;

        for(int i=0;i<n;i++)
        {
            cin>>k;
            sum=sum+k;
        }
        cout<<min(sum,m)<<endl;
    }

}


#include<iostream>
#include<algorithm>
using namespace std;
/*int main()
{
    long long int  t,k,m,sum=0;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int n,m;
        cin>>n>>m;

        for(int i=0;i<n;i++)
        {
            cin>>k;
            sum=sum+k;
        }
        cout<<min(sum,m)<<endl;
    }*/
int main()
{
	long long int  test;
	cin>>test;
	while(test--)
	{
		long long int  n,m;
		cin>>n>>m;
		long long int  s=0;
		for(long long int  i=1;i<=n;i++)
		{
			long long int x;
			cin>>x;
			s=s+x;
		}
		cout<<min(s,m)<<"\n";
	}
	return 0;
}
}


#include<iostream>
#include<algorithm>
using namespace std;
/*int main()
{
    long long int  t,k,m,sum=0;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int n,m;
        cin>>n>>m;

        for(int i=0;i<n;i++)
        {
            cin>>k;
            sum=sum+k;
        }
        cout<<min(sum,m)<<endl;
    }*/
int main()
{
	long long int  test;
	cin>>test;
	while(test--)
	{
		long long int  n,m;
		cin>>n>>m;
		long long int  s=0;
		for(ll i=1;i<=n;i++)
		{
			long long int x;
			cin>>x;
			s=s+x;
		}
		cout<<min(s,m)<<"\n";
	}
	return 0;
}
}


#include<iostream>
using namespace std;
int main()
{
    int t,k,m;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int n,m;
        cin>>n>>m;

        for(int i=0;i<n;i++)
        {
            cin>>k;
        }
        cout<<m<<endl;
    }

}


#include<iostream>
#include<algorithm>
using namespace std;
/*int main()
{
    long long int  t,k,m,sum=0;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int n,m;
        cin>>n>>m;

        for(int i=0;i<n;i++)
        {
            cin>>k;
            sum=sum+k;
        }
        cout<<min(sum,m)<<endl;
    }*/
int main()
{
	long long int  test;
	cin>>test;
	while(test--)
	{
		long long int  n,m;
		cin>>n>>m;
		long long int  s=0;
		for(long long int i=1;i<=n;i++)
		{
			long long int x;
			cin>>x;
			s=s+x;
		}
		cout<<min(s,m)<<"\n";
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int t,k,m,sum=0;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int n,m;
        cin>>n>>m;

        for(int i=0;i<n;i++)
        {
            cin>>k;
            sum=sum+k;
        }
        cout<<min(sum,m)<<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll test;
	cin>>test;
	while(test--)
	{
		ll n,m;
		cin>>n>>m;
		ll s=0;
		for(ll i=1;i<=n;i++)
		{
			ll x;
			cin>>x;
			s=s+x;
		}
		cout<<min(s,m)<<"\n";
	}
	return 0;
}


#include <bits/stdc++.h>

#define forr(i, n) for(ll i = n-1; i >= 0; i--)
#define forn(i, n) for(ll i = 0; i < n; i++)
#define forab(i, a, n) for(ll i = a; i < n; i++)
#define forabr(i, a, b) for(ll i = b; i > a; i--)
#define endl '\n'
#define s seconde
#define f first
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long ll;
const int MAXN = 1e6;

int n, m, t, a;
ll s;

int main(){
    fast_io;
    cin >> t;
    while(t--){
        cin >> n >> m;
        s = 0;
        forn(i, n){
            cin >> a;
            s += a;
            if(s >= m){
                s = m;
            }
        }
        cout << s << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

#define forr(i, n) for(ll i = n-1; i >= 0; i--)
#define forn(i, n) for(ll i = 0; i < n; i++)
#define forab(i, a, n) for(ll i = a; i < n; i++)
#define forabr(i, a, b) for(ll i = b; i > a; i--)
#define endl '\n'
#define s seconde
#define f first
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long ll;
const int MAXN = 1e6;

int n, m, t, a, s;

int main(){
    fast_io;
    cin >> t;
    while(t--){
        cin >> n >> m;
        forn(i, n){
            cin >> a;
            s += a;
            if(s > m){
                s = m;
                break;
            }
        }
        cout << s << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

#define forr(i, n) for(ll i = n-1; i >= 0; i--)
#define forn(i, n) for(ll i = 0; i < n; i++)
#define forab(i, a, n) for(ll i = a; i < n; i++)
#define forabr(i, a, b) for(ll i = b; i > a; i--)
#define endl '\n'
#define s seconde
#define f first
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long ll;
const int MAXN = 1e6;

int n, m, t, a;
ll s;

int main(){
    fast_io;
    cin >> t;
    while(t--){
        cin >> n >> m;
        forn(i, n){
            cin >> a;
            s += a;
            if(s >= m){
                s = m;
                break;
            }
        }
        cout << s << endl;
        s = 0;
    }
    return 0;
}


#include <bits/stdc++.h>

#define forr(i, n) for(ll i = n-1; i >= 0; i--)
#define forn(i, n) for(ll i = 0; i < n; i++)
#define forab(i, a, n) for(ll i = a; i < n; i++)
#define forabr(i, a, b) for(ll i = b; i > a; i--)
#define endl '\n'
#define s seconde
#define f first
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long ll;
const int MAXN = 1e6;

int n, m, t, a;
ll s;

int main(){
    fast_io;
    cin >> t;
    while(t--){
        cin >> n >> m;
        s = 0;
        forn(i, n){
            cin >> a;
            s += a;
        }
        cout << max(s, m) << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

#define forr(i, n) for(ll i = n-1; i >= 0; i--)
#define forn(i, n) for(ll i = 0; i < n; i++)
#define forab(i, a, n) for(ll i = a; i < n; i++)
#define forabr(i, a, b) for(ll i = b; i > a; i--)
#define endl '\n'
#define s seconde
#define f first
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long ll;
const int MAXN = 1e6;

int n, m, t, a;
ll s;

int main(){
    fast_io;
    cin >> t;
    while(t--){
        cin >> n >> m;
        s = 0;
        forn(i, n){
            cin >> a;
            s += a;
            if(s >= m){
                s = m;
                break;
            }
        }
        cout << s << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

#define forr(i, n) for(ll i = n-1; i >= 0; i--)
#define forn(i, n) for(ll i = 0; i < n; i++)
#define forab(i, a, n) for(ll i = a; i < n; i++)
#define forabr(i, a, b) for(ll i = b; i > a; i--)
#define endl '\n'
#define s seconde
#define f first
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long ll;
const int MAXN = 1e6;

int n, m, t, a, s;

int main(){
    fast_io;
    cin >> t;
    while(t--){
        cin >> n >> m;
        s = -n;
        forn(i, n){
            cin >> a;
            if(s > m){
                s = m;
                break;
            }
            s += a;
        }
        cout << s;
    }
    return 0;
}


#include <bits/stdc++.h>

#define forr(i, n) for(ll i = n-1; i >= 0; i--)
#define forn(i, n) for(ll i = 0; i < n; i++)
#define forab(i, a, n) for(ll i = a; i < n; i++)
#define forabr(i, a, b) for(ll i = b; i > a; i--)
#define endl '\n'
#define s seconde
#define f first
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long ll;
const int MAXN = 1e6;

int n, m, t, a, s;

int main(){
    fast_io;
    cin >> t;
    while(t--){
        cin >> n >> m;
        s = -n;
        forn(i, n){
            cin >> a;
            if(s > m){
                s = m;
                break;
            }
            s += a;
        }
        cout << s << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main() {
	int num,  n, m,sum=0,q;
	cin >> num;

	while (num--) {
	    cin >> n >> m;
		int *arr = new int[n];
		for (int x = 0; x < n; x++) {
			cin >> arr[x];
			sum += arr[x];

		}cout << min(sum,m)<<"\n";
	}

}


#include<bits/stdc++.h>
#define wow 2000000
using namespace std;
int main() {
	long long num, arr[wow], n, m,sum=0,q;
	cin >> num;
	arr[num]={};
	while (num--, cin >> n >> m) {
		for (int x = 0; x < n; x++) {
			cin >> arr[x];
			sum += arr[x];

		}if (sum > m)cout << m<<"\n";
		else cout << sum<<"\n";
	}

}


#include<bits/stdc++.h>
using namespace std;
int main() {
	int num,  n, m,sum=0,q;
	cin >> num;

	while (num--) {
	    cin >> n >> m;
	    sum=0;
		int *arr = new int[n];
		for (int x = 0; x < n; x++) {
			cin >> arr[x];
			sum += arr[x];

		}cout << min(sum,m)<<"\n";
	}

}


#include<bits/stdc++.h>
using namespace std;
int main() {
	int num, arr[100], n, m,sum=0,q;
	cin >> num;
	arr[num] = {};
	while (num--, cin >> n >> m) {
		for (int x = 0; x < n; x++) {
			cin >> arr[x];
			sum += arr[x];

		}cout << min(sum,m)<<"\n";
	}

}


#include<bits/stdc++.h>
using namespace std;
int main() {
	int num,  n, m,sum=0,q;
	cin >> num;

	while (num--, cin >> n >> m) {
		int *arr = new int[num];
		for (int x = 0; x < n; x++) {
			cin >> arr[x];
			sum += arr[x];

		}cout << min(sum,m)<<"\n";
	}

}


#include<bits/stdc++.h>
using namespace std;
int main() {
	long long num, arr[100000], n, m,sum=0,q;
	cin >> num;
	arr[num] = {};
	while (num--, cin >> n >> m) {
		for (int x = 0; x < n; x++) {
			cin >> arr[x];
			sum += arr[x];

		}cout << min(sum,m)<<"\n";
	}

}


#include<bits/stdc++.h>
using namespace std;
int main() {
	int num, arr[100], n, m,sum=0,q;
	cin >> num;
	arr[num];
	while (num--, cin >> n >> m) {
		for (int x = 0; x < n; x++) {
			cin >> arr[x];
			sum += arr[x];
		}if (sum >= m)cout << m<<"\n";
		else cout << sum<<"\n";
	}
}


#include <bits/stdc++.h>

using namespace std;

int n,i,a,b,score[10000000],sum,j;

int main(){
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a>>b;

            for(j=0;j<a;j++){
                cin>>score[j];

                    sum +=score[j];

            }
            if(sum-score[0]>=b-score[0]){
                cout<<b<<endl;
        }else{
            cout<<sum<<endl;
        }
        sum=0;

    }
}


#include <bits/stdc++.h>

using namespace std;

int n,i,a,b,score[10000000],sum,j;

int main(){
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a>>b;
            for(j=0;j<a;j++){
                cin>>score[j];
                if(j>=1){
                    sum +=score[j];
                }
            }
            if(sum>=b-score[0]){
                cout<<b<<endl;
        }else{
            cout<<sum<<endl;
        }
        sum=0;
    }
}


#include <bits/stdc++.h>

using namespace std;

int n,i,a,b,score[10000000],sum,j;

int main(){
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a>>b;
            for(j=0;j<a;j++){
                cin>>score[j];
                if(j>=1){
                    sum +=score[j];
                }
            }
            if(sum>=b-score[0]){
                cout<<b<<endl;
        }else{
            cout<<sum<<endl;
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

int n,i,a,b,score[10000000],sum,j;

int main(){
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a>>b;
        if(a>1){
            for(j=0;j<a;j++){
                cin>>score[j];

                    sum +=score[j];

            }
            if(sum-score[0]>=b-score[0]){
                cout<<b<<endl;
        }else{
            cout<<sum<<endl;
        }
        sum=0;
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

int n,i,a,b,score[10000000],sum,j;

int main(){
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a>>b;
        if(a>1){
            for(j=0;j<a;j++){
                cin>>score[j];
                if(j>=1){
                    sum +=score[j];
                }
            }
            if(sum>=b-score[0]){
                cout<<b<<endl;
        }else{
            cout<<sum<<endl;
        }
        sum=0;
        }else{
            cin>>score[0];
            cout<<b-score[0];
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

int n,i,a,b,score[10000000],sum;

int main(){
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a>>b;
            for(i=0;i<a;i++){
                cin>>score[i];
                if(i>=1){
                    sum +=score[i];
                }
            }
            if(sum>=b-score[0]){
                cout<<b<<endl;
        }else{
            cout<<sum<<endl;
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

int n,i,a,b,score[10000000],sum,j;

int main(){
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a>>b;
        if(a>1){
            for(j=0;j<a;j++){
                cin>>score[j];
                if(j>=1){
                    sum +=score[j];
                }
            }
            if(sum>=b-score[0]){
                cout<<b<<endl;
        }else{
            cout<<sum<<endl;
        }
        sum=0;
        }else{
            cin>>score[0];
            cout<<b-score[0]<<endl;
        }
    }
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
  int t, n, m, a;
  // int add = 0;
  cin >> t;
  for (int i =0; i < t; i++)
  {
    cin >> n >> m;
    for(int i = 0; i < n; i++)
    {
      cin >> a;
    }
    if(n!=1)
    {
      // add += a;
      cout << m << endl;
    }
    else if(n==1)
    {
      cout << a << endl;
    }
  }
}


#include<bits/stdc++.h>

using namespace std;

int main()
{

  int t, n, m, a, add;
  vector <int> vec;
  cin >> t;
  for (int i =0; i < t; i++)
  {
    cin >> n >> m;
    for(int i = 0; i < n; i++)
    {
      cin >> a;
    }
    cout << m << endl;
  }
}


#include<bits/stdc++.h>

using namespace std;

int main()
{

  int t, n, m, a, add;
  vector <int> vec;
  cin >> t;
  for (int i =0; i < t; i++)
  {
    cin >> n >> m;

    for(int i = 0; i < n; i++)
    {
      cin >> a;
    }
    if(a == 0)
    {
      cout << 0 << endl;
    }
    else
    {
      cout << m << endl;
    }
  }
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int t;
	cin >> t;
	while(t--){
		int n, m, a, sum=0;
		cin >> n >> m;
		for(int i=0; i<n; i++){
			cin >> a;
			sum+=a;
		}
		cout << min(sum, m) << "\n";
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int t, n, m, a, sum=0;
	cin >> t;
	while(t--){
		cin >> n >> m;
		for(int i=0; i<n; i++){
			cin >> a;
			sum+=a;
		}
		cout << min(sum, m) << "\n";
	}
}


#include <iostream>
#include<algorithm>
using namespace std;
int arr[10005];
int n,c;
;
int main() {
cin>>n;
for(int i=0;i<n ;i++)
{
     int x,s,sum=0; cin>>x>>s;
     for(int j=0 ;j<x ;j++)
     {
         cin>>arr[j];
        sum+=arr[j];
     }
     sort(arr,arr+x);
     if(sum<=s)
     {
         cout<<sum<<endl;
         continue;
     }
    for(int m=x-1 ; m>=0 ;m--)
    {
    if(c+arr[m]<=s)
    c+=arr[m];
    if(c==s)
    continue;
    }

        cout<<c<<endl;
        c=0;
}
    return 0;
}


#include <iostream>
using namespace std;
int arr[10005];
int n,c;
;
int main() {
cin>>n;
for(int i=0;i<n ;i++)
{
     int x,s,sum=0; cin>>x>>s;
     for(int j=0 ;j<x ;j++)
     {
         cin>>arr[j];
        sum+=arr[j];
     }
     if(sum<=s)
     {
         cout<<sum<<endl;
         continue;
     }
    for(int m=x-1 ; m>=0 ;m--)
    {
    if(c+arr[m]<=s)
    c+=arr[m];
    if(c==s)
    continue;
    }

        cout<<c<<endl;
        c=0;
}
    return 0;
}


#include <iostream>
using namespace std;
int arr[10005];
int n,c;
float sum;
int main() {
cin>>n;
for(int i=0;i<n ;i++)
{
     float x,s; cin>>x>>s;
     for(int j=0 ;j<x ;j++)
     {
         cin>>arr[j];
        sum+=arr[j];
     }
     if(sum<=s)
     {
         cout<<sum<<endl;
         continue;
     }
    for(int m=x-1 ; m>=0 ;m--)
    {
    if(c+arr[m]<=s)
    c+=arr[m];
    if(c==s)
    continue;
    }

        cout<<c<<endl;
        c=0;
        sum=0;
}
    return 0;
}


#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int arr[100005];
int main() {
    int t; cin>>t;
    while(t--)
    {
        int n,k,sum=0; cin>>n>>k;
        for(int i=0 ;i<n ;++i)
        {
            cin>>arr[i];
            sum+=arr[i];
        }
        if(sum>=k)
            cout<<k<<end
            else
                cout<<sum<<endl;

    }
return 0;
}


#include <iostream>
using namespace std;
int arr[10005];
int n,c;
float sum;
int main() {
cin>>n;
for(int i=0;i<n ;i++)
{
     float x,s; cin>>x>>s;
     for(int j=0 ;j<x ;j++)
     {
         cin>>arr[j];
        sum+=arr[j];
     }
     if(sum<=s)
     {
         cout<<sum<<endl;
         continue;
     }
    for(int m=x-1 ; m>=0 ;m--)
    {
    if(c+arr[m]<=s)
    c+=arr[m];
    if(c==s)
    continue;
    }

        cout<<c<<endl;
        c=0;
}
    return 0;
}


#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int arr[100005];
int main() {
    int t; cin>>t;
    while(t--)
    {
        int n,k,sum=0; cin>>n>>k;
        for(int i=0 ;i<n ;++i)
        {
            cin>>arr[i];
            sum+=arr[i];
        }
        if(sum>=k)
            cout<<k<<endl;
            else
                cout<<sum<<endl;

    }
return 0;
}


#include <iostream>
using namespace std;
int arr[10005];
int n,c;
float sum;
int main() {
cin>>n;
for(int i=0;i<n ;i++)
{
     float x,s; cin>>x>>s;
     for(int j=0 ;j<x ;j++)
     {
         cin>>arr[j];
        sum+=arr[j];
     }
     if(sum<=s)
     {
         cout<<sum<<endl;
         continue;
     }
    for(int m=x-1 ; m>=0 ;m--)
    {
    if(c+arr[m]<=s)
    c+=arr[m];
    if(c==s)
    break;
    }

        cout<<c<<endl;
        c=0;
}
    return 0;
}


#include <iostream>
#include<vector>

using namespace std;

int main()
{

    int t,sum=0,n,m,i,j,a;
    cin>>t;
    for (i=0; i<t; i++)
    {
        cin>>n>>m;
        for (j=0; j<n; j++)
        {
            cin>>a;
            sum=sum+a;
        }
        if(sum<m)
        cout<<sum;
        else
        cout<<m;
        sum=0;
    }
    }


#include <iostream>
#include<vector>

using namespace std;

int main()
{

    int t,sum=0,n,m,i,j,a;
    cin>>t>>endl;
    for (i=0; i<t; i++)
    {
        cin>>n >>m>>endl;
        for (j=0; j<n; j++)
        {
            cin>>a >> ;
            sum=sum+a;
        }
        if(sum<m)
        cout<<sum;
        else
        cout<<m;
        sum=0;
    }
    }


#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <ctime>
#include <cmath>
#include <deque>

using namespace std;

void change(long long& ans, int i, vector<long long>& v, vector<bool>& used)
{
	if (i == 0)
		{
			if (v[i] > v[i + 1])
				ans += v[i], used[i] = 1;
		}
		else if (i == n - 1)
		{
			if (v[i] > v[i - 1])
				ans += v[i], used[i] = 1;
		}
		else if (v[i] > v[i - 1] && v[i] > v[i + 1])
			ans += v[i], used[i] = 1;
		else if (v[i] < v[i - 1] && v[i] < v[i + 1])
			ans -= v[i], used[i] = -1;
}

void resolve()
{
	int n, q;
	cin >> n >> q;
	vector<long long> v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	vector<int> used(n, 0);
	long long ans = 0;
	if (n == 1)
	{
		cout << v[0] << '\n';
		goto skip;
	}
	for (int i = 0; i < n; i++)
	    change(ans, i, v, used);
	cout << ans << '\n';
skip:
	for (int t = 0; t < q; t++)
	{
		int l, r;
		cin >> l >> r;
		if (n == 1)
		{
			cout << v[0];
			continue;
		}
		l--;
		r--;

		for (int i = max(0, l - 1); i <= min(n - 1, l + 1); i++)
		{
			if (used[i] == -1)
				ans += v[i], used[i] = 0;
			else if (used[i] == 1)
				ans -= v[i], used[i] = 0;
		}
		for (int i = max(l + 2, r - 1); i <= min(n - 1, r + 1); i++)
		{
			if (used[i] == -1)
				ans += v[i], used[i] = 0;
			else if (used[i] == 1)
				ans -= v[i], used[i] = 0;
		}

		swap(v[l], v[r]);
#ifdef _DEBUG
		for (int i = 0; i < n; i++)
			cout << v[i] << ' ';
		cout << '\n';
#endif
		for (int i = max(0, l - 1); i <= min(n - 1, l + 1); i++)
            change(ans, i, v, used);
		for (int i = max(l + 2, r - 1); i <= min(n - 1, r + 1); i++)
		    change(ans, i, v, used);
		cout << ans << '\n';
	}
}

int main()
{
	srand(time(0) + clock());
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	long long t;
	cin >> t;
	for (long long i = 0; i < t; i++)
	{
		resolve();
	}
}


#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <ctime>
#include <cmath>
#include <deque>

using namespace std;

void change(long long& ans, int i, vector<long long>& v, vector<int>& used)
{
    int n = v.size();
	if (i == 0)
		{
			if (v[i] > v[i + 1])
				ans += v[i], used[i] = 1;
		}
		else if (i == n - 1)
		{
			if (v[i] > v[i - 1])
				ans += v[i], used[i] = 1;
		}
		else if (v[i] > v[i - 1] && v[i] > v[i + 1])
			ans += v[i], used[i] = 1;
		else if (v[i] < v[i - 1] && v[i] < v[i + 1])
			ans -= v[i], used[i] = -1;
}

void resolve()
{
	int n, q;
	cin >> n >> q;
	vector<long long> v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	vector<int> used(n, 0);
	long long ans = 0;
	if (n == 1)
	{
		cout << v[0] << '\n';
		goto skip;
	}
	for (int i = 0; i < n; i++)
	    change(ans, i, v, used);
	cout << ans << '\n';
skip:
	for (int t = 0; t < q; t++)
	{
		int l, r;
		cin >> l >> r;
		if (n == 1)
		{
			cout << v[0];
			continue;
		}
		l--;
		r--;

		for (int i = max(0, l - 1); i <= min(n - 1, l + 1); i++)
		{
			if (used[i] == -1)
				ans += v[i], used[i] = 0;
			else if (used[i] == 1)
				ans -= v[i], used[i] = 0;
		}
		for (int i = max(l + 2, r - 1); i <= min(n - 1, r + 1); i++)
		{
			if (used[i] == -1)
				ans += v[i], used[i] = 0;
			else if (used[i] == 1)
				ans -= v[i], used[i] = 0;
		}

		swap(v[l], v[r]);
#ifdef _DEBUG
		for (int i = 0; i < n; i++)
			cout << v[i] << ' ';
		cout << '\n';
#endif
		for (int i = max(0, l - 1); i <= min(n - 1, l + 1); i++)
            change(ans, i, v, used);
		for (int i = max(l + 2, r - 1); i <= min(n - 1, r + 1); i++)
		    change(ans, i, v, used);
		cout << ans << '\n';
	}
}

int main()
{
	srand(time(0) + clock());
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	long long t;
	cin >> t;
	for (long long i = 0; i < t; i++)
	{
		resolve();
	}
}


#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <ctime>
#include <cmath>
#include <deque>

using namespace std;

void change(long long& ans, int i, int r, vector<long long>& v, vector<bool>& used)
{
	int n = v.size();
	if (i == 0)
	{
		if (v[0] > v[1])
		{
			if (used[1])
				ans -= v[1], used[1] = 0;
			ans += v[0], used[0] = 1;
		}
		return;
	}
	if (i == n - 1)
	{
		if (v[n - 1] > v[n - 2])
		{
			if (used[n - 2])
				ans -= v[n - 2], used[n - 2] = 0;
			ans += v[n - 1], used[n - 1] = 1;
		}
		return;
	}
	if (v[i] < v[i - 1] && v[i] < v[i + 1])
		used[i] = 1, ans -= v[i];
	if (v[i] > v[i - 1] && v[i] > v[i + 1])
		ans += v[i], used[i] = 1;

	if (v[i] > v[i - 1] && used[i - 1])
		used[i - 1] = 0, ans -= v[i - 1];
	if (v[i] > v[i + 1] && used[i + 1])
		used[i + 1] = 0, ans -= v[i + 1];
	if (v[i] < v[i - 1] && (i == 1 || v[i - 1] > v[i - 2]))
		ans += v[i - 1], used[i - 1] = 1;
	if (v[i] < v[i + 1] && (i = n - 2 || v[i + 1] > v[i + 1]))
		ans += v[i + 1], used[i + 1] = 1;
}

void resolve()
{
	int n, q;
	cin >> n >> q;
	vector<long long> v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	vector<bool> used(n, 0);
	long long ans = 0;
	for (int i = 0; i < n; i++)
	{
		if (i == 0)
		{
			if (v[i] > v[i + 1])
				ans += v[i], used[i] = 1;
		}
		else if (i == n - 1)
		{
			if (v[i] > v[i - 1])
				ans += v[i], used[i] = 1;
		}
		else if (v[i] > v[i - 1] && v[i] > v[i + 1])
			ans += v[i], used[i] = 1;
		else if (v[i] < v[i - 1] && v[i] < v[i + 1])
			ans -= v[i], used[i] = 1;
	}
	cout << ans << '\n';
	for (int t = 0; t < q; t++)
	{
		int l, r;
		cin >> l >> r;
		if (n == 1)
		{
			cout << v[0];
			continue;
		}
		l--;
		r--;

		for (int i = max(0, l - 1); i <= min(n - 1, l + 1); i++)
			if (used[i])
				ans -= v[i], used[i] = 0;
		for (int i = max(l + 2, r - 1); i <= min(n - 1, r + 1); i++)
			if (used[i])
				ans -= v[i], used[i] = 0;

		swap(v[l], v[r]);
		for (int i = max(0, l - 1); i <= min(n - 1, l + 1); i++)
		{
			if (i == 0)
			{
				if (v[i] > v[i + 1])
					ans += v[i], used[i] = 1;
			}
			else if (i == n - 1)
			{
				if (v[i] > v[i - 1])
					ans += v[i], used[i] = 1;
			}
			else if (v[i] > v[i - 1] && v[i] > v[i + 1])
				ans += v[i], used[i] = 1;
			else if (v[i] < v[i - 1] && v[i] < v[i + 1])
				ans -= v[i], used[i] = 1;
		}
		for (int i = max(l + 2, r - 1); i <= min(n - 1, r + 1); i++)
		{
			if (i == 0)
			{
				if (v[i] > v[i + 1])
					ans += v[i], used[i] = 1;
			}
			else if (i == n - 1)
			{
				if (v[i] > v[i - 1])
					ans += v[i], used[i] = 1;
			}
			else if (v[i] > v[i - 1] && v[i] > v[i + 1])
				ans += v[i], used[i] = 1;
			else if (v[i] < v[i - 1] && v[i] < v[i + 1])
				ans -= v[i], used[i] = 1;
		}
		cout << ans << '\n';
	}
}

int main()
{
	srand(time(0) + clock());
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	long long t;
	cin >> t;
	for (long long i = 0; i < t; i++)
	{
		resolve();
	}
}


#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <ctime>
#include <cmath>
#include <deque>

using namespace std;

void resolve()
{
	int n, q;
	cin >> n >> q;
	vector<int> v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	vector<long long> dp(n);
	long long mn = 0;
	long long ans = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		int mn1 = min(mn, v[i] - ans);
		ans = max(ans, v[i] - mn);
		mn = mn1;
	}
	cout << ans;
}

int main()
{
	srand(time(0) + clock());
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	long long t;
	cin >> t;
	for (long long i = 0; i < t; i++)
	{
		resolve();
		cout << '\n';
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define LL long long
using namespace std;
#pragma GCC optimize(2)
LL t, n, q, a[300010], dp[300010][2];
int main() {
    scanf("%lld", &t);
    while (t--) {
        scanf("%lld%lld", &n, &q);
        for (int i = 1; i <= n; i++) {
            dp[i][0] = 0;
            dp[i][1] = 0;
        }
        for (int i = 1; i <= n; i++) {
            scanf("%lld", &a[i]);
            dp[i][1] = a[i];
        }
        for (int i = 2; i <= n; i++) {
            dp[i][1] = max(dp[i - 1][1], max(dp[i - 1][0] + a[i], dp[i][1]));
            dp[i][0] = max(dp[i - 1][0], max(dp[i - 1][1] - a[i], dp[i][0]));
        }
        printf("%lld\n", max(dp[n][1], dp[n][0]));
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
int t, n, q, a[300010], dp[300010][2];
int main() {
    scanf("%d", &t);
    while (t--) {
        scanf("%d%d", &n, &q);
        for (int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
            dp[i][0] = 0;
            dp[i][1] = 0;
        }
        for (int i = 1; i <= n; i++) {
            dp[i][1] = max(dp[i - 1][1],dp[i - 1][0] + a[i]);
            dp[i][0] = max(dp[i - 1][0],dp[i - 1][1] - a[i]);
        }
        printf("%d\n", max(dp[n][1], dp[n][0]));
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define LL long long
using namespace std;
#pragma GCC optimize(2)
LL t, n, q, a[300010], dp[300010][2];
int main() {
    scanf("%lld", &t);
    while (t--) {
        scanf("%lld%lld", &n, &q);
        for (int i = 1; i <= n; i++) {
            scanf("%lld", &a[i]);
            dp[i][0] = 0;
            dp[i][1] = 0;
        }
        for (int i = 1; i <= n; i++) {
            dp[i][1] = max(dp[i - 1][1],dp[i - 1][0] + a[i]);
            dp[i][0] = max(dp[i - 1][0],dp[i - 1][1] - a[i]);
        }
        printf("%lld\n", max(dp[n][1], dp[n][0]));
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
int t,n,q,a[300010],dp[300010][2];
int main() {
    scanf("%d", &t);
    while (t--) {
        scanf("%d%d", &n,&q);
        memset(dp, 0, sizeof(dp));
        for (int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
            dp[i][1] = a[i];
        }
        for (int i = 1; i <= n; i++) {
            for (int j = i - 1; j > 0; j--) {
                dp[i][1] = max(dp[j][1],max(dp[j][0]+a[i], dp[i][1]));
                dp[i][0] = max(dp[j][0],max(dp[j][1]-a[i], dp[i][0]));
            }
        }
        printf("%d\n", max(dp[n][1], dp[n][0]));
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626
const int mod = 1000000007;
#define fo1(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
#define mk(arr,n,type)  type *arr=new type[n];

int mx=INT_MIN;
int dp[100000][2];
void max_sum(int arr[],int n,int si,int sm,int cnt){
    if(si==n){
        mx=max(mx,sm);
        dp[si][cnt]=mx;
        // cout<<mx<<endl;
        return;
    }
    if(dp[si][cnt]!=-1){
        return;
    }
    if(cnt==0){
        max_sum(arr,n,si+1,sm+arr[si],1);
        max_sum(arr,n,si+1,sm,cnt);
    }else{
        max_sum(arr,n,si+1,sm-arr[si],0);
        max_sum(arr,n,si+1,sm,cnt);
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int t;
    cin>>t;
    while(t--){
        int n,q;
        cin>>n>>q;
        mk(arr,n,int);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        memset(dp,-1,sizeof(dp));
        max_sum(arr,n,0,0,0);
        cout<<mx<<endl;
        mx=INT_MIN;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626
const int mod = 1000000007;
#define fo1(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
#define mk(arr,n,type)  type *arr=new type[n];

ll mx=LLONG_MIN;
ll dp[300005][2];
void max_sum(int arr[],int n,int si,ll sm,int cnt){
    if(si==n){
        mx=max(mx,sm);
        dp[si][cnt]=mx;
        // cout<<mx<<endl;
        return;
    }
    if(dp[si][cnt]!=-1){
        mx=dp[si][cnt];
        return;
    }
    if(cnt==0){
        max_sum(arr,n,si+1,sm+arr[si],1);
        max_sum(arr,n,si+1,sm,cnt);
    }else{
        max_sum(arr,n,si+1,sm-arr[si],0);
        max_sum(arr,n,si+1,sm,cnt);
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int t;
    cin>>t;
    while(t--){
        int n,q;
        cin>>n>>q;
        mk(arr,n,int);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        memset(dp,-1,sizeof(dp));
        max_sum(arr,n,0,0,0);
        cout<<mx<<endl;
        mx=LLONG_MIN;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626
const int mod = 1000000007;
#define fo1(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
#define mk(arr,n,type)  type *arr=new type[n];

int mx=INT_MIN;
int dp[100000][2];
void max_sum(int arr[],int n,int si,int sm,int cnt){
    if(si==n){
        mx=max(mx,sm);
        dp[si][cnt]=mx;
        // cout<<mx<<endl;
        return;
    }
    if(dp[si][cnt]!=-1){
        mx=dp[si][cnt];
        return;
    }
    if(cnt==0){
        max_sum(arr,n,si+1,sm+arr[si],1);
        max_sum(arr,n,si+1,sm,cnt);
    }else{
        max_sum(arr,n,si+1,sm-arr[si],0);
        max_sum(arr,n,si+1,sm,cnt);
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int t;
    cin>>t;
    while(t--){
        int n,q;
        cin>>n>>q;
        mk(arr,n,int);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        memset(dp,-1,sizeof(dp));
        max_sum(arr,n,0,0,0);
        cout<<mx<<endl;
        mx=INT_MIN;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626
const int mod = 1000000007;
#define fo1(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
#define mk(arr,n,type)  type *arr=new type[n];

int mx=INT_MIN;
void max_sum(int arr[],int n,int si,int sm,int cnt){
    if(si==n){
        mx=max(mx,sm);
        // cout<<mx<<endl;
        return;
    }
    if(cnt==0){
        max_sum(arr,n,si+1,sm+arr[si],1);
        max_sum(arr,n,si+1,sm,cnt);
    }else{
        max_sum(arr,n,si+1,sm-arr[si],0);
        max_sum(arr,n,si+1,sm,cnt);
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int t;
    cin>>t;
    while(t--){
        int n,q;
        cin>>n>>q;
        mk(arr,n,int);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        max_sum(arr,n,0,0,0);
        cout<<mx<<endl;
        mx=INT_MIN;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626
const int mod = 1000000007;
#define fo1(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
#define mk(arr,n,type)  type *arr=new type[n];

ll dp[300005][2];
int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int t;
    cin>>t;
    while(t--){
        int n,q;
        cin>>n>>q;
        mk(arr,n,ll);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        //If i have 1 pikachu
        dp[0][0] =arr[0];
        dp[0][1]=0;
        for(int i=1;i<n;i++){
            dp[i][0]=max(dp[i-1][1]+arr[i],dp[i-1][0]);
            dp[i][1]=max(dp[i-1][0]-arr[i],dp[i-1][1]);
        }
        cout<<max(dp[n-1][0],dp[n-1][1])<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626
const int mod = 1000000007;
#define fo1(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
#define mk(arr,n,type)  type *arr=new type[n];

int mx=INT_MIN;
int dp[300000][2];
void max_sum(int arr[],int n,int si,int sm,int cnt){
    if(si==n){
        mx=max(mx,sm);
        dp[si][cnt]=mx;
        // cout<<mx<<endl;
        return;
    }
    if(dp[si][cnt]!=-1){
        mx=dp[si][cnt];
        return;
    }
    if(cnt==0){
        max_sum(arr,n,si+1,sm+arr[si],1);
        max_sum(arr,n,si+1,sm,cnt);
    }else{
        max_sum(arr,n,si+1,sm-arr[si],0);
        max_sum(arr,n,si+1,sm,cnt);
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int t;
    cin>>t;
    while(t--){
        int n,q;
        cin>>n>>q;
        mk(arr,n,int);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        memset(dp,-1,sizeof(dp));
        max_sum(arr,n,0,0,0);
        cout<<mx<<endl;
        mx=INT_MIN;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626
const int mod = 1000000007;
#define fo1(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
#define mk(arr,n,type)  type *arr=new type[n];

ll mx=LLONG_MIN;
ll dp[300000][2];
void max_sum(int arr[],int n,int si,ll sm,int cnt){
    if(si==n){
        mx=max(mx,sm);
        dp[si][cnt]=mx;
        // cout<<mx<<endl;
        return;
    }
    if(dp[si][cnt]!=-1){
        mx=dp[si][cnt];
        return;
    }
    if(cnt==0){
        max_sum(arr,n,si+1,sm+arr[si],1);
        max_sum(arr,n,si+1,sm,cnt);
    }else{
        max_sum(arr,n,si+1,sm-arr[si],0);
        max_sum(arr,n,si+1,sm,cnt);
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int t;
    cin>>t;
    while(t--){
        int n,q;
        cin>>n>>q;
        mk(arr,n,int);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        memset(dp,-1,sizeof(dp));
        max_sum(arr,n,0,0,0);
        cout<<mx<<endl;
        mx=LLONG_MIN;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
        sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
        {
sim > struct rge
{
        c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
        ~debug()
        {
                cerr << endl;
        }
        eni(!=) cerr << boolalpha << i;
        ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
        ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
                *this << ", " + 2 * (it == d.b) << *it;
        ris << "]";
}
#else
        sim dor(const c &)
        {
                ris;
        }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define pb push_back
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

void solve()
{
        ll n, q; cin >> n >> q;
        vector<ll> a(n);
        for (int i = 0; i < n; ++i)
        {
                cin >> a[i];
        }
        ll res = a[0];
        for (int i = 1; i < n - 1; ++i)
        {
                if (a[i - 1] < a[i] && a[i + 1] < a[i] && res == a[0])
                {
                        res = a[i];
                }
                else if (a[i - 1] < a[i] && a[i + 1] < a[i])
                {
                        res += a[i];
                }
                else if (a[i] < a[i - 1] && a[i] < a[i + 1]) res -= a[i];
        }
        if (res == a[0]) cout << *max_element(all(a)) << endl;
        else if (res < *max_element(all(a))) cout << res + *max_element(all(a))  << endl;
        else cout << res << endl;
}

int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int t; cin >> t;
        while (t--) solve();
}
/*
*/


#include <bits/stdc++.h>

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
        sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
        {
sim > struct rge
{
        c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
        ~debug()
        {
                cerr << endl;
        }
        eni(!=) cerr << boolalpha << i;
        ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
        ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
                *this << ", " + 2 * (it == d.b) << *it;
        ris << "]";
}
#else
        sim dor(const c &)
        {
                ris;
        }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define pb push_back
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

void solve()
{
        ll n, q; cin >> n >> q;
        vector<ll> a(n);
        for (int i = 0; i < n; ++i)
        {
                cin >> a[i];
        }
        ll res = *max_element(all(a));
        for (int i = 1; i < n - 1; ++i)
        {
                if (a[i] != n && (a[i - 1] < a[i] && a[i + 1] < a[i])) res += a[i];
                else if (a[i] < a[i - 1] && a[i] < a[i + 1]) res -= a[i];
        }
        cout << res << endl;
}

int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int t; cin >> t;
        while (t--) solve();
}
/*
*/


#include <bits/stdc++.h>

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
        sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
        {
sim > struct rge
{
        c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
        ~debug()
        {
                cerr << endl;
        }
        eni(!=) cerr << boolalpha << i;
        ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
        ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
                *this << ", " + 2 * (it == d.b) << *it;
        ris << "]";
}
#else
        sim dor(const c &)
        {
                ris;
        }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define pb push_back
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

void solve()
{
        int n, q; cin >> n >> q;
        vector<int> a(n);
        for (int i = 0; i < n; ++i)
        {
                cin >> a[i];
        }
        ll res = 0;
        for (int i = 0; i < n; ++i)
        {
                if (a[i] == n || (a[i - 1] < a[i] && a[i + 1] < a[i])) res += a[i];
                else if (a[i] < a[i - 1] && a[i] < a[i + 1] && res != 0) res -= a[i];
        }
        cout << res << endl;
}

int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int t; cin >> t;
        while (t--) solve();
}
/*
*/


#include <bits/stdc++.h>

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
        sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
        {
sim > struct rge
{
        c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
        ~debug()
        {
                cerr << endl;
        }
        eni(!=) cerr << boolalpha << i;
        ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
        ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
                *this << ", " + 2 * (it == d.b) << *it;
        ris << "]";
}
#else
        sim dor(const c &)
        {
                ris;
        }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define pb push_back
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

void solve()
{
        ll n, q; cin >> n >> q;
        vector<ll> a(n);
        for (int i = 0; i < n; ++i)
        {
                cin >> a[i];
        }
        ll res = 0, cnt = 0;
        for (int i = 1; i < n - 1; ++i)
        {
                if (a[i - 1] < a[i] && a[i + 1] < a[i])
                {
                        res += a[i];
                        cnt++;
                }
                else if (a[i] < a[i - 1] && a[i] < a[i + 1])
                {
                        res -= a[i];
                        cnt++;
                }
        }
        if (cnt % 2 == 0) cout << res + a[n - 1] << endl;
        else cout << res << endl;
}

int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int t; cin >> t;
        while (t--) solve();
}
/*
*/


#include <bits/stdc++.h>

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
        sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
        {
sim > struct rge
{
        c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
        ~debug()
        {
                cerr << endl;
        }
        eni(!=) cerr << boolalpha << i;
        ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
        ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
                *this << ", " + 2 * (it == d.b) << *it;
        ris << "]";
}
#else
        sim dor(const c &)
        {
                ris;
        }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define pb push_back
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

void solve()
{
        ll n, q; cin >> n >> q;
        vector<ll> a(n);
        for (int i = 0; i < n; ++i)
        {
                cin >> a[i];
        }
        ll res = 0;
        for (int i = 1; i < n - 1; ++i)
        {
                if (a[i - 1] < a[i] && a[i + 1] < a[i]) res += a[i];
                else if (a[i] < a[i - 1] && a[i] < a[i + 1]) res -= a[i];
        }
        if (res < *max_element(all(a))) cout << res + *max_element(all(a)) << endl;
        else cout << res << endl;
}

int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int t; cin >> t;
        while (t--) solve();
}
/*
*/