#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; ++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()
{
        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;
        if (a[0] < a[1])
        {
                res = 0;
        }
        else
        {
                res = a[0];
                cnt++;
        }
        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;

using ll = long long;

void test_case() {
	int n, q;
	cin >> n >> q;

	vector<int> a(n);
	for (int i = 0; i <n; ++i) {
		cin >> a[i];
	}

	if (n == 1) {
		cout << a[0] << endl;
		return;
	}

	int ans = 0;
	int i = 0;
	for (; i < n - 1; ++i) {
		if (a[i] > a[i + 1]) {
			ans = a[i];
			break;
		}
	}
	if (i == n - 1) {
		ans = a[i];
	}
	++i;

	while (i < n) {
		while (i + 1 < n and a[i] > a[i + 1]) {
			++i;
		}
		if (i == n -1) {
			break;
		}

		int j = i;
		while (i + 1 < n and a[i] < a[i + 1]) {
			++i;
		}
		ans += a[i] - a[j];
	}
	cout << ans << endl;
}

int main () {
	int tests;
	cin >> tests;

	for (int i=0;i<tests;++i) {
		test_case();
	}
	return 0;
}


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

using ll = long long;

void test_case() {
	int n, q;
	cin >> n >> q;

	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	vector<vector<int>> dp(n, vector<int>(4));
	dp[n - 1][0] = a[n-1];
	dp[n - 1][1] = -a[n-1];
	dp[n - 1][2] = a[n-1];

	for (int i = n - 2; i > 0; --i) {
		dp[i][0] = max(a[i] + max(dp[i + 1][1], dp[i+1][3]), a[i]);
		dp[i][1] = -a[i] + max(dp[i + 1][0], dp[i+1][2]);
		dp[i][2] = max(dp[i][0], dp[i + 1][2]);
		dp[i][3] = max(dp[i + 1][3], dp[i][1]);
	}

	if (n > 1) {
		dp[0][0] = max(a[0] + max(dp[1][1], dp[1][3]), a[0]);
	}

	int ans = 0;
	for (int i = 0; i < n; ++i) {
		ans = max(ans, dp[i][0]);
	}
	cout << ans << endl;

}

int main () {
	int tests;
	cin >> tests;

	for (int i=0;i<tests;++i) {
		test_case();
	}
	return 0;
}


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

using ll = long long;

void test_case() {
	int n, q;
	cin >> n >> q;

	vector<ll> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	vector<vector<ll>> dp(n, vector<ll>(4));
	dp[n - 1][0] = a[n-1];
	dp[n - 1][1] = -a[n-1];
	dp[n - 1][2] = a[n-1];

	for (int i = n - 2; i > 0; --i) {
		dp[i][0] = max(a[i] + max(dp[i + 1][1], dp[i+1][3]), a[i]);
		dp[i][1] = -a[i] + max(dp[i + 1][0], dp[i+1][2]);
		dp[i][2] = max(dp[i][0], dp[i + 1][2]);
		dp[i][3] = max(dp[i + 1][3], dp[i][1]);
	}

	if (n > 1) {
		dp[0][0] = max(a[0] + max(dp[1][1], dp[1][3]), a[0]);
	}

	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		ans = max(ans, dp[i][0]);
	}
	cout << ans << endl;
}

int main () {
	int tests;
	cin >> tests;

	for (int i=0;i<tests;++i) {
		test_case();
	}
	return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;
//int input........
template <typename T> inline void readline(T &n) {n = 0; int f = 1; register int ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readline(T &n, TT &m) { readline(n); readline(m); }
template <typename T, typename TT, typename TTT> inline void readline(T &n, TT &m, TTT &l) { readline(n, m); readline(l);}
// long long input........
template <typename T> inline void readlinel(T &n) {n = 0; long long f = 1; register long long ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readlinel(T &n, TT &m) { readlinel(n); readlinel(m); }
template <typename T, typename TT, typename TTT> inline void readlinel(T &n, TT &m, TTT &l) { readlinel(n, m); readlinel(l);}
//debug..........
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}
//............ignore it..................//
int dx[8]= {1,0,-1,0,-1,-1,1,1};int dy[8]= {0,1,0,-1,-1,1,-1,1}; int tc = 1;
#define F first
#define S second
#define pb  push_back
#define mp make_pair
#define Pi atan(1)*4
#define ll  long long int
#define happy cin.tie(0);
#define point(x) setprecision(x)
#define coding ios::sync_with_stdio(false);
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;
void print(int n){printf("%d\n", n);}
void Print(int n){printf("%d ", n);}
void print(int n,int m){printf("%d ",n);printf("%d ",m);}
void print(int n,int m,int k){printf("%d ",n);printf("%d ",m);printf("%d ",k);}
void print(ll n){printf("%I64d\n", n);}
void Print(ll n){printf("%I64d ", n);}
void print(ll n,ll m){printf("%I64d ",n);printf("%I64d ",m);}
void print(ll n,ll m,ll k){printf("%I64d ",n);printf("%I64d ",m);printf("%I64d ",k);}
int length(long long x){int l = 0;for(long long i=x;i;i/=10)l++;return l;}
int length(string s){return s.size();}
const int M           	= 1e9 + 7;
long long pow(long long a,long long n){ll res = 1;while(n){if(n&1) res = ((res%M)*(a%M))%M;a = ((a%M)*(a%M))%M;n>>=1;}return res%M;}

#define   pr 	pair<int, int>
#define   vpr 	vector<pr>
#define   vi   	std::vector<int>
#define   vll  	std::vector<ll>
#define   all(n) n.begin(),n.end()

const int Inf           = (int)2e9 + 5;
const ll  Lnf           = (ll)2e18 + 5;
const int N             = 4e5 + 5;
const int NN            = 1e6 + 5;

int solve()
{
	//happy coding

	int n,q;
	cin>>n>>q;
	int a[n];
	for(int i =0;i<n;i++){
		cin>>a[i];
	}

	vi v;
	int l = 0;
	for(int i=1;i<n-1;i++){
		if(a[i]>a[i-1] and a[i]> a[i+1]){
			v.pb(a[i]);
			l = i;
		}else if(a[i]<a[i-1] and a[i]< a[i+1]){
			v.pb(a[i]);
			l = i;
		}
	}

	if(v.size()&1^1){
		int mx=  0;
		for(int i=l+1;i<n;i++){
			mx = max(a[i],mx);
		}
		v.pb(mx);
	}

	int sum = 0;

	for(int i=0;i<v.size();i++){
		if(i&1^1)sum += v[i];
		else sum -= v[i];
	}
	//vout(v);

	cout<<sum<<endl;

	return 0;
	//error();
}
int main(){
	int test = 1;
	readline(test);//(void)getchar();
	while (test--)solve();return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;
//int input........
template <typename T> inline void readline(T &n) {n = 0; int f = 1; register int ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readline(T &n, TT &m) { readline(n); readline(m); }
template <typename T, typename TT, typename TTT> inline void readline(T &n, TT &m, TTT &l) { readline(n, m); readline(l);}
// long long input........
template <typename T> inline void readlinel(T &n) {n = 0; long long f = 1; register long long ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readlinel(T &n, TT &m) { readlinel(n); readlinel(m); }
template <typename T, typename TT, typename TTT> inline void readlinel(T &n, TT &m, TTT &l) { readlinel(n, m); readlinel(l);}
//debug..........
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}
//............ignore it..................//
int dx[8]= {1,0,-1,0,-1,-1,1,1};int dy[8]= {0,1,0,-1,-1,1,-1,1}; int tc = 1;
#define F first
#define S second
#define pb  push_back
#define mp make_pair
#define Pi atan(1)*4
#define ll  long long int
#define happy cin.tie(0);
#define point(x) setprecision(x)
#define coding ios::sync_with_stdio(false);
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;
void print(int n){printf("%d\n", n);}
void Print(int n){printf("%d ", n);}
void print(int n,int m){printf("%d ",n);printf("%d ",m);}
void print(int n,int m,int k){printf("%d ",n);printf("%d ",m);printf("%d ",k);}
void print(ll n){printf("%I64d\n", n);}
void Print(ll n){printf("%I64d ", n);}
void print(ll n,ll m){printf("%I64d ",n);printf("%I64d ",m);}
void print(ll n,ll m,ll k){printf("%I64d ",n);printf("%I64d ",m);printf("%I64d ",k);}
int length(long long x){int l = 0;for(long long i=x;i;i/=10)l++;return l;}
int length(string s){return s.size();}
const int M           	= 1e9 + 7;
long long pow(long long a,long long n){ll res = 1;while(n){if(n&1) res = ((res%M)*(a%M))%M;a = ((a%M)*(a%M))%M;n>>=1;}return res%M;}

#define   pr 	pair<int, int>
#define   vpr 	vector<pr>
#define   vi   	std::vector<int>
#define   vll  	std::vector<ll>
#define   all(n) n.begin(),n.end()

const int Inf           = (int)2e9 + 5;
const ll  Lnf           = (ll)2e18 + 5;
const int N             = 4e5 + 5;
const int NN            = 1e6 + 5;

int solve()
{
	//happy coding

	int n,q;
	cin>>n>>q;
	int a[n];
	for(int i =0;i<n;i++){
		cin>>a[i];
	}

	vi v;
	int l = 0;
	for(int i=1;i<n-1;i++){
		if(i == 1){
			if(a[i-1]> a[i])v.pb(a[i-1]);
		}
		if(a[i]>a[i-1] and a[i]> a[i+1]){
			v.pb(a[i]);
			l = i;
		}else if( a[i]<a[i-1] and a[i]< a[i+1]){
			v.pb(a[i]);
			l = i;
		}
	}

	if(v.size()&1^1){
		int mx=  0;
		for(int i=l+1;i<n;i++){
			mx = max(a[i],mx);
		}
		v.pb(mx);
	}

	int sum = 0;

	for(int i=0;i<v.size();i++){
		if(i&1^1)sum += v[i];
		else sum -= v[i];
	}
	//vout(v);

	cout<<sum<<endl;

	return 0;
	//error();
}
int main(){
	int test = 1;
	readline(test);//(void)getchar();
	while (test--)solve();return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;
//int input........
template <typename T> inline void readline(T &n) {n = 0; int f = 1; register int ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readline(T &n, TT &m) { readline(n); readline(m); }
template <typename T, typename TT, typename TTT> inline void readline(T &n, TT &m, TTT &l) { readline(n, m); readline(l);}
// long long input........
template <typename T> inline void readlinel(T &n) {n = 0; long long f = 1; register long long ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readlinel(T &n, TT &m) { readlinel(n); readlinel(m); }
template <typename T, typename TT, typename TTT> inline void readlinel(T &n, TT &m, TTT &l) { readlinel(n, m); readlinel(l);}
//debug..........
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}
//............ignore it..................//
int dx[8]= {1,0,-1,0,-1,-1,1,1};int dy[8]= {0,1,0,-1,-1,1,-1,1}; int tc = 1;
#define F first
#define S second
#define pb  push_back
#define mp make_pair
#define Pi atan(1)*4
#define ll  long long int
#define happy cin.tie(0);
#define point(x) setprecision(x)
#define coding ios::sync_with_stdio(false);
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;
void print(int n){printf("%d\n", n);}
void Print(int n){printf("%d ", n);}
void print(int n,int m){printf("%d ",n);printf("%d ",m);}
void print(int n,int m,int k){printf("%d ",n);printf("%d ",m);printf("%d ",k);}
void print(ll n){printf("%I64d\n", n);}
void Print(ll n){printf("%I64d ", n);}
void print(ll n,ll m){printf("%I64d ",n);printf("%I64d ",m);}
void print(ll n,ll m,ll k){printf("%I64d ",n);printf("%I64d ",m);printf("%I64d ",k);}
int length(long long x){int l = 0;for(long long i=x;i;i/=10)l++;return l;}
int length(string s){return s.size();}
const int M           	= 1e9 + 7;
long long pow(long long a,long long n){ll res = 1;while(n){if(n&1) res = ((res%M)*(a%M))%M;a = ((a%M)*(a%M))%M;n>>=1;}return res%M;}

#define   pr 	pair<int, int>
#define   vpr 	vector<pr>
#define   vi   	std::vector<int>
#define   vll  	std::vector<ll>
#define   all(n) n.begin(),n.end()

const int Inf           = (int)2e9 + 5;
const ll  Lnf           = (ll)2e18 + 5;
const int N             = 4e5 + 5;
const int NN            = 1e6 + 5;

int solve()
{
	//happy coding

	ll n,q;
	cin>>n>>q;
	ll a[n];
	for(ll i =0;i<n;i++){
		cin>>a[i];
	}

	if(n == 1){
		cout<<a[0]<<endl;
		return 0;
	}

	vll v;
	ll l = 0;
	for(ll i=1;i<n-1;i++){
		if(i == 1){
			if(a[i-1]> a[i])v.pb(a[i-1]);
		}
		if(a[i]>a[i-1] and a[i]> a[i+1]){
			v.pb(a[i]);
			l = i;
		}else if( a[i]<a[i-1] and a[i]< a[i+1]){
			v.pb(a[i]);
			l = i;
		}
	}

	if(v.size()&1^1){
		ll mx=  0;
		if(l != 0)l++;
		for(ll i=l;i<n;i++){
			mx = max(a[i],mx);
		}
		v.pb(mx);
	}

	ll sum = 0;

	for(ll i=0;i<v.size();i++){
		if(i&1^1)sum += v[i];
		else sum -= v[i];
	}
	//vout(v);

	cout<<sum<<endl;

	return 0;
	//error();
}
int main(){
	int test = 1;
	readline(test);//(void)getchar();
	while (test--)solve();return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr>
#define pr pair<int, int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;
int length(long long x){int l = 0;for(long long i=x;i;i/=10)l++;return l;}

#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

ll ar[N],dp[N][2];

int solve()
{
	//happy coding

	int n,q;
	cin>>n>>q;

	for(int i=1;i<=n;i++){
		cin>>ar[i];
		dp[i][1] = dp[i][0] = 0;
	}

	for(int i=1;i<=n;i++){
		dp[i][0] = max(dp[i-1][0],ar[i]+dp[i-1][1]);
		dp[i][1] = max(dp[i-1][1],dp[i-1][0]-ar[i]);
	}

	cout<<max(dp[n][0],dp[n][1])<<endl;

	return 0;
}
int main(){
	int test = 1;
  	scanf("%d", &test);
  	while (test--)solve();return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr>
#define pr pair<int, int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;
int length(long long x){int l = 0;for(long long i=x;i;i/=10)l++;return l;}

#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

ll ar[N],dp[N][2];

int solve()
{
	//happy coding

	int n,q;
	cin>>n>>q;

	for(int i=1;i<=n;i++){
		cin>>ar[i];
		dp[i][1] = dp[i][0] = 0LL;
	}

	for(int i=1;i<=n;i++){
		dp[i][0] = max(dp[i-1][0],ar[i]+dp[i-1][1]);
		dp[i][1] = max(dp[i-1][1],dp[i-1][0]-ar[i]);
	}

	cout<<max(dp[n][0],dp[n][1])<<endl;

	return 0;
}
int main(){
	int test = 1;
  	scanf("%d", &test);
  	while (test--)solve();return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;
//int input........
template <typename T> inline void readline(T &n) {n = 0; int f = 1; register int ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readline(T &n, TT &m) { readline(n); readline(m); }
template <typename T, typename TT, typename TTT> inline void readline(T &n, TT &m, TTT &l) { readline(n, m); readline(l);}
// long long input........
template <typename T> inline void readlinel(T &n) {n = 0; long long f = 1; register long long ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readlinel(T &n, TT &m) { readlinel(n); readlinel(m); }
template <typename T, typename TT, typename TTT> inline void readlinel(T &n, TT &m, TTT &l) { readlinel(n, m); readlinel(l);}
//debug..........
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}
//............ignore it..................//
int dx[8]= {1,0,-1,0,-1,-1,1,1};int dy[8]= {0,1,0,-1,-1,1,-1,1}; int tc = 1;
#define F first
#define S second
#define pb  push_back
#define mp make_pair
#define Pi atan(1)*4
#define ll  long long int
#define happy cin.tie(0);
#define point(x) setprecision(x)
#define coding ios::sync_with_stdio(false);
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;
void print(int n){printf("%d\n", n);}
void Print(int n){printf("%d ", n);}
void print(int n,int m){printf("%d ",n);printf("%d ",m);}
void print(int n,int m,int k){printf("%d ",n);printf("%d ",m);printf("%d ",k);}
void print(ll n){printf("%I64d\n", n);}
void Print(ll n){printf("%I64d ", n);}
void print(ll n,ll m){printf("%I64d ",n);printf("%I64d ",m);}
void print(ll n,ll m,ll k){printf("%I64d ",n);printf("%I64d ",m);printf("%I64d ",k);}
int length(long long x){int l = 0;for(long long i=x;i;i/=10)l++;return l;}
int length(string s){return s.size();}
const int M           	= 1e9 + 7;
long long pow(long long a,long long n){ll res = 1;while(n){if(n&1) res = ((res%M)*(a%M))%M;a = ((a%M)*(a%M))%M;n>>=1;}return res%M;}

#define   pr 	pair<int, int>
#define   vpr 	vector<pr>
#define   vi   	std::vector<int>
#define   vll  	std::vector<ll>
#define   all(n) n.begin(),n.end()

const int Inf           = (int)2e9 + 5;
const ll  Lnf           = (ll)2e18 + 5;
const int N             = 4e5 + 5;
const int NN            = 1e6 + 5;

int solve()
{
	//happy coding

	int n,q;
	cin>>n>>q;
	int a[n];
	for(int i =0;i<n;i++){
		cin>>a[i];
	}

	vi v;
	int l = 0;
	bool f = false;
	for(int i=1;i<n-1;i++){
		if(a[i]>a[i-1] and a[i]> a[i+1]){
			v.pb(a[i]);
			l = i;
			f = true;
		}else if(f and a[i]<a[i-1] and a[i]< a[i+1]){
			v.pb(a[i]);
			l = i;
		}
	}

	if(v.size()&1^1){
		int mx=  0;
		for(int i=l+1;i<n;i++){
			mx = max(a[i],mx);
		}
		v.pb(mx);
	}

	int sum = 0;

	for(int i=0;i<v.size();i++){
		if(i&1^1)sum += v[i];
		else sum -= v[i];
	}
	//vout(v);

	cout<<sum<<endl;

	return 0;
	//error();
}
int main(){
	int test = 1;
	readline(test);//(void)getchar();
	while (test--)solve();return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;
//int input........
template <typename T> inline void readline(T &n) {n = 0; int f = 1; register int ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readline(T &n, TT &m) { readline(n); readline(m); }
template <typename T, typename TT, typename TTT> inline void readline(T &n, TT &m, TTT &l) { readline(n, m); readline(l);}
// long long input........
template <typename T> inline void readlinel(T &n) {n = 0; long long f = 1; register long long ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readlinel(T &n, TT &m) { readlinel(n); readlinel(m); }
template <typename T, typename TT, typename TTT> inline void readlinel(T &n, TT &m, TTT &l) { readlinel(n, m); readlinel(l);}
//debug..........
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}
//............ignore it..................//
int dx[8]= {1,0,-1,0,-1,-1,1,1};int dy[8]= {0,1,0,-1,-1,1,-1,1}; int tc = 1;
#define F first
#define S second
#define pb  push_back
#define mp make_pair
#define Pi atan(1)*4
#define ll  long long int
#define happy cin.tie(0);
#define point(x) setprecision(x)
#define coding ios::sync_with_stdio(false);
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;
void print(int n){printf("%d\n", n);}
void Print(int n){printf("%d ", n);}
void print(int n,int m){printf("%d ",n);printf("%d ",m);}
void print(int n,int m,int k){printf("%d ",n);printf("%d ",m);printf("%d ",k);}
void print(ll n){printf("%I64d\n", n);}
void Print(ll n){printf("%I64d ", n);}
void print(ll n,ll m){printf("%I64d ",n);printf("%I64d ",m);}
void print(ll n,ll m,ll k){printf("%I64d ",n);printf("%I64d ",m);printf("%I64d ",k);}
int length(long long x){int l = 0;for(long long i=x;i;i/=10)l++;return l;}
int length(string s){return s.size();}
const int M           	= 1e9 + 7;
long long pow(long long a,long long n){ll res = 1;while(n){if(n&1) res = ((res%M)*(a%M))%M;a = ((a%M)*(a%M))%M;n>>=1;}return res%M;}

#define   pr 	pair<int, int>
#define   vpr 	vector<pr>
#define   vi   	std::vector<int>
#define   vll  	std::vector<ll>
#define   all(n) n.begin(),n.end()

const int Inf           = (int)2e9 + 5;
const ll  Lnf           = (ll)2e18 + 5;
const int N             = 4e5 + 5;
const int NN            = 1e6 + 5;

int solve()
{
	//happy coding

	ll n,q;
	cin>>n>>q;
	ll a[n];
	for(ll i =0;i<n;i++){
		cin>>a[i];
	}

	if(n == 1){
		cout<<a[0]<<endl;
		return 0;
	}

	vll v;
	ll l = 0;
	for(ll i=1;i<n-1;i++){
		if(i == 1){
			if(a[i-1]> a[i])v.pb(a[i-1]);
		}
		if(a[i]>a[i-1] and a[i]> a[i+1]){
			v.pb(a[i]);
			l = i;
		}else if( a[i]<a[i-1] and a[i]< a[i+1]){
			v.pb(a[i]);
			l = i;
		}
	}

	if(v.size()&1^1){
		ll mx=  0;
		for(ll i=l+1;i<n;i++){
			mx = max(a[i],mx);
		}
		v.pb(mx);
	}

	ll sum = 0;

	for(ll i=0;i<v.size();i++){
		if(i&1^1)sum += v[i];
		else sum -= v[i];
	}
	//vout(v);

	cout<<sum<<endl;

	return 0;
	//error();
}
int main(){
	int test = 1;
	readline(test);//(void)getchar();
	while (test--)solve();return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr>
#define pr pair<int, int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;
int length(long long x){int l = 0;for(long long i=x;i;i/=10)l++;return l;}

#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 3e5 + 5;
ll vis[N],res[N];

ll ar[N],dp[N][2];

int solve()
{
	//happy coding

	int n,q;
	cin>>n>>q;

	for(int i=1;i<=n;i++){
		cin>>ar[i];
		dp[i][1] = dp[i][0] = 0LL;
	}

	for(int i=1;i<=n;i++){
		dp[i][0] = max(dp[i-1][0],ar[i]+dp[i-1][1]);
		dp[i][1] = max(dp[i-1][1],dp[i-1][0]-ar[i]);
	}

	cout<<max(dp[n][0],dp[n][1])<<endl;

	return 0;
}
int main(){
	int test = 1;
  	scanf("%d", &test);
  	while (test--)solve();return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;
//int input........
template <typename T> inline void readline(T &n) {n = 0; int f = 1; register int ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readline(T &n, TT &m) { readline(n); readline(m); }
template <typename T, typename TT, typename TTT> inline void readline(T &n, TT &m, TTT &l) { readline(n, m); readline(l);}
// long long input........
template <typename T> inline void readlinel(T &n) {n = 0; long long f = 1; register long long ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readlinel(T &n, TT &m) { readlinel(n); readlinel(m); }
template <typename T, typename TT, typename TTT> inline void readlinel(T &n, TT &m, TTT &l) { readlinel(n, m); readlinel(l);}
//debug..........
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}
//............ignore it..................//
int dx[8]= {1,0,-1,0,-1,-1,1,1};int dy[8]= {0,1,0,-1,-1,1,-1,1}; int tc = 1;
#define F first
#define S second
#define pb  push_back
#define mp make_pair
#define Pi atan(1)*4
#define ll  long long int
#define happy cin.tie(0);
#define point(x) setprecision(x)
#define coding ios::sync_with_stdio(false);
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;
void print(int n){printf("%d\n", n);}
void Print(int n){printf("%d ", n);}
void print(int n,int m){printf("%d ",n);printf("%d ",m);}
void print(int n,int m,int k){printf("%d ",n);printf("%d ",m);printf("%d ",k);}
void print(ll n){printf("%I64d\n", n);}
void Print(ll n){printf("%I64d ", n);}
void print(ll n,ll m){printf("%I64d ",n);printf("%I64d ",m);}
void print(ll n,ll m,ll k){printf("%I64d ",n);printf("%I64d ",m);printf("%I64d ",k);}
int length(long long x){int l = 0;for(long long i=x;i;i/=10)l++;return l;}
int length(string s){return s.size();}
const int M           	= 1e9 + 7;
long long pow(long long a,long long n){ll res = 1;while(n){if(n&1) res = ((res%M)*(a%M))%M;a = ((a%M)*(a%M))%M;n>>=1;}return res%M;}

#define   pr 	pair<int, int>
#define   vpr 	vector<pr>
#define   vi   	std::vector<int>
#define   vll  	std::vector<ll>
#define   all(n) n.begin(),n.end()

const int Inf           = (int)2e9 + 5;
const ll  Lnf           = (ll)2e18 + 5;
const int N             = 4e5 + 5;
const int NN            = 1e6 + 5;

int solve()
{
	//happy coding

	int n,q;
	cin>>n>>q;
	int a[n];
	for(int i =0;i<n;i++){
		cin>>a[i];
	}

	if(n == 1){
		cout<<a[0]<<endl;
		return 0;
	}

	vi v;
	int l = 0;
	for(int i=1;i<n-1;i++){
		if(i == 1){
			if(a[i-1]> a[i])v.pb(a[i-1]);
		}
		if(a[i]>a[i-1] and a[i]> a[i+1]){
			v.pb(a[i]);
			l = i;
		}else if( a[i]<a[i-1] and a[i]< a[i+1]){
			v.pb(a[i]);
			l = i;
		}
	}

	if(v.size()&1^1){
		int mx=  0;
		for(int i=l+1;i<n;i++){
			mx = max(a[i],mx);
		}
		v.pb(mx);
	}

	int sum = 0;

	for(int i=0;i<v.size();i++){
		if(i&1^1)sum += v[i];
		else sum -= v[i];
	}
	//vout(v);

	cout<<sum<<endl;

	return 0;
	//error();
}
int main(){
	int test = 1;
	readline(test);//(void)getchar();
	while (test--)solve();return 0;
}


#include<bits/stdc++.h>
const int N =50010;
int a[N];
typedef long long ll;
using namespace std;
int main (){
	int t;
	cin>>t;
	while(t--){
		int n ,q;
		cin>>n>>q;
		for(int i=1 ;i<=n;i++)cin>>a[i];
		ll ans =0;
		int jde =0;
		for(int i=1;i<=n;i++){
			if(a[i]<a[i-1]&&jde==0){
				ans+=a[i-1];
				jde=1;
			}
			if(a[i]>a[i-1]&&jde==1){
				ans-=a[i-1];
				jde=0;
			}
		}
		if(jde==0)ans+=a[n];
		cout<<ans <<endl;

	}
}


#include<bits/stdc++.h>
const int N =50010;
int a[N];
typedef long long ll;
using namespace std;
int main (){
	int t;
	cin>>t;
	while(t--){
		int n ,q;
		cin>>n>>q;
		for(int i=1 ;i<=n;i++)cin>>a[i];
		ll ans =0;
		int jde =0;
		for(int i=1;i<=n;i++){
			if(a[i]<a[i-1]&&jde==0){
				ans+=a[i-1];
				jde=1;
			}
			if(a[i]>a[i-1]&&jde==1){
				ans-=a[i-1];
				jde=0;
			}
		}
		if(jde==0)ans+=a[n];
		printf("%d\n",ans);

	}
}


#include<bits/stdc++.h>
const int N =500010;
int a[N];
typedef long long ll;
using namespace std;
int main (){
	int t;
	cin>>t;
	while(t--){
		int n ,q;
		cin>>n>>q;
		for(int i=1 ;i<=n;i++)cin>>a[i];
		ll ans =0;
		int jde =0;
		for(int i=1;i<=n;i++){
			if(a[i]<a[i-1]&&jde==0){
				ans+=a[i-1];
				jde=1;
			}
			if(a[i]>a[i-1]&&jde==1){
				ans-=a[i-1];
				jde=0;
			}
		}
		if(jde==0)ans+=a[n];
		cout<<ans <<endl;

	}
}


#include<bits/stdc++.h>
const int N =300010;
int a[N];
using namespace std;
int main (){
	int t;
	cin>>t;
	while(t--){
		int n ,q;
		int m=0;
		cin>>n>>q;
		for(int i=1 ;i<=n;i++){
			cin>>a[i];
		}
		int ans =0;
		int jde =0;
		for(int i=1;i<=n;i++){
			if(a[i]<a[i-1]&&jde==0){
				ans+=a[i-1];
				jde=1;
			}
			if(a[i]>a[i-1]&&jde==1){
				ans-=a[i-1];
				jde=0;
			}
		}
		if(jde==0)ans+=a[n];
		printf("%d\n",ans);

	}
}


#include<bits/stdc++.h>
const int N =50010;
int a[N];
typedef long long ll;
using namespace std;
int main (){
	int t;
	cin>>t;
	while(t--){
		int n ,q;
		int m=0;
		cin>>n>>q;
		for(int i=1 ;i<=n;i++){
			cin>>a[i];
			if(a[i]>m)m=a[i];
		}
		ll ans =0;
		int jde =0;
		for(int i=1;i<=n;i++){
			if(a[i]<a[i-1]&&jde==0){
				ans+=a[i-1];
				jde=1;
			}
			if(a[i]>a[i-1]&&jde==1){
				ans-=a[i-1];
				jde=0;
			}
		}
		if(jde==0)ans+=a[n];
		printf("%d\n",max(m,ans));

	}
}


#include<bits/stdc++.h>
const int N =50010;
int a[N];
using namespace std;
int main (){
	int t;
	cin>>t;
	while(t--){
		int n ,q;
		int m=0;
		cin>>n>>q;
		for(int i=1 ;i<=n;i++){
			cin>>a[i];
			if(a[i]>m)m=a[i];
		}
		int ans =0;
		int jde =0;
		for(int i=1;i<=n;i++){
			if(a[i]<a[i-1]&&jde==0){
				ans+=a[i-1];
				jde=1;
			}
			if(a[i]>a[i-1]&&jde==1){
				ans-=a[i-1];
				jde=0;
			}
		}
		if(jde==0)ans+=a[n];
		printf("%d\n",max(m,ans));

	}
}


// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
void dump_func()
{
    cerr << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&h, Tail &&... t)
{
    cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...);
}
#define dump(...)                                                                                \
    cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), \
        cerr << "*/\n\n";
typedef long long ll;

int sum(int n)
{
    return n * (n + 1) / 2;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    cin >> tt;
    int n, q;
    while (tt--) {
        cin >> n >> q;
        vector<ll> a(n);
        for (int i = 0; i < n; i++)
            cin >> a[i];
        // [0 = max, 1 = min]
        vector<vector<ll>> dp(2, vector<ll>(n + 1, 0));

        for (int i = n - 1; i >= 0; i--) {
            dp[0][i] = max(dp[0][i + 1], a[i] - dp[1][i + 1]);
            dp[1][i] = min(dp[1][i + 1], a[i] - dp[0][i + 1]);
        }

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


// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
void dump_func()
{
    cerr << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&h, Tail &&... t)
{
    cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...);
}
#define dump(...)                                                                                \
    cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), \
        cerr << "*/\n\n";
typedef long long ll;

vector<ll> memo(90000, 0);

ll fib(ll n)
{
    if (memo[n] != 0) {
        return memo[n];
    }
    if (n < 2) {
        memo[n] = 1;
        return memo[n];
    }
    else {
        memo[n] = fib(n - 1) + fib(n - 2);
        return memo[n];
    }
}

ll fib_n(ll n)
{
    if (n < 2) {
        return 1;
    }
    else {
        return fib_n(n - 1) + fib_n(n - 2);
    }
}

bool implies(bool b1, bool b2)
{
    return !b1 || b2;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt, n, q;
    cin >> tt;
    while (tt--) {
        cin >> n >> q;
        vector<ll> a(n);
        bool inc = false;
        ll prev = 0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }

        vector<ll> pol;
        for (int i = 0; i < n; i++) {
            // minimal, maximal
            if (implies(0 < i - 1, a[i - 1] < a[i]) && implies(i + 1 < n, a[i + 1] < a[i])) {
                pol.push_back(a[i]);
            }
            else if (implies(0 < i - 1, a[i] < a[i - 1]) && implies(i + 1 < n, a[i] < a[i + 1])) {
                pol.push_back(a[i]);
            }
        }
        // for (auto e : pol) {
        //     cout << e << '\n';
        // }
        ll res = 0;
        int n = pol.size();
        // 最初と最後は極値
        assert(n >= 2);
        for (int i = 0; i < n - 1; i++) {
            if (pol[i] - pol[i + 1] > 0)
                res += pol[i] - pol[i + 1];
        }
        // 最後をたす極小でも, 引いた分を足す
        res += pol[n - 1];
        cout << res << '\n';
    }

    return 0;
}


// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
void dump_func()
{
    cerr << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&h, Tail &&... t)
{
    cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...);
}
#define dump(...)                                                                                \
    cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), \
        cerr << "*/\n\n";
typedef long long ll;

int sum(int n)
{
    return n * (n + 1) / 2;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    cin >> tt;
    int n, q;
    while (tt--) {
        cin >> n >> q;
        vector<ll> a(n);
        for (int i = 0; i < n; i++)
            cin >> a[i];
        //
        // [add = 0, minus = 1,][i]
        // [i, n);
        vector<vector<ll>> dp(2, vector<ll>(n + 1, 0));

        for (int i = n - 1; i >= 0; i--) {
            dp[0][i] = max(dp[0][i + 1], dp[1][i + 1] + a[i]);
            dp[1][i] = max(dp[1][i + 1], dp[0][i + 1] - a[i]);
        }

        cout << max(dp[0][0], dp[1][0]) << endl;
    }
    return 0;
}


// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
void dump_func()
{
    cerr << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&h, Tail &&... t)
{
    cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...);
}
#define dump(...)                                                                                \
    cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), \
        cerr << "*/\n\n";
typedef long long ll;

bool implies(bool b1, bool b2)
{
    return !b1 || b2;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt, n, q;
    cin >> tt;
    while (tt--) {
        cin >> n >> q;
        vector<ll> a(n);
        ll prev = 0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }

        vector<ll> pol;
        for (int i = 0; i < n; i++) {
            // minimal, maximal
            if (implies(0 < i - 1, a[i - 1] < a[i]) && implies(i + 1 < n, a[i + 1] < a[i])) {
                pol.push_back(a[i]);
            }
            else if (implies(0 < i - 1, a[i] < a[i - 1]) && implies(i + 1 < n, a[i] < a[i + 1])) {
                pol.push_back(a[i]);
            }
        }
        ll res = 0;
        int m = pol.size();
        for (int i = 0; i < m - 1; i++) {
            if (pol[i] - pol[i + 1] > 0)
                res += pol[i] - pol[i + 1];
        }
        // 最後をたす. 極小でも, 引いた分を足す
        res += pol[m - 1];
        cout << res << '\n';
    }

    return 0;
}


// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
void dump_func()
{
    cerr << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&h, Tail &&... t)
{
    cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...);
}
#define dump(...)                                                                                \
    cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), \
        cerr << "*/\n\n";
typedef long long ll;

int sum(int n)
{
    return n * (n + 1) / 2;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    cin >> tt;
    int n, q;
    while (tt--) {
        cin >> n >> q;
        vector<ll> a(n);
        for (int i = 0; i < n; i++)
            cin >> a[i];
        //
        // [add = 0, minus = 1,][i]
        // [i, n);
        vector<vector<ll>> dp(2, vector<ll>(n + 1, 0));

        for (int i = n - 1; i >= 0; i--) {
            dp[0][i] = max(dp[0][i + 1], dp[1][i + 1] + a[i]);
            dp[1][i] = max(dp[1][i + 1], dp[0][i + 1] - a[i]);
        }

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


// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
void dump_func()
{
    cerr << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&h, Tail &&... t)
{
    cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...);
}
#define dump(...)                                                                                \
    cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), \
        cerr << "*/\n\n";
typedef long long ll;

bool implies(bool b1, bool b2)
{
    return !b1 || b2;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt, n, q;
    cin >> tt;
    while (tt--) {
        cin >> n >> q;
        vector<ll> a(n);
        bool inc = false;
        ll prev = 0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }

        vector<ll> pol;
        for (int i = 0; i < n; i++) {
            // minimal, maximal
            if (implies(0 < i - 1, a[i - 1] <= a[i]) && implies(i + 1 < n, a[i + 1] <= a[i])) {
                pol.push_back(a[i]);
            }
            else if (implies(0 < i - 1, a[i] <= a[i - 1]) && implies(i + 1 < n, a[i] < a[i + 1])) {
                pol.push_back(a[i]);
            }
        }
        // for (auto e : pol) {
        //     cout << e << '\n';
        // }
        ll res = 0;
        int n = pol.size();
        // 最初と最後は極値
        assert(n >= 2);
        for (int i = 0; i < n - 1; i++) {
            if (pol[i] - pol[i + 1] > 0)
                res += pol[i] - pol[i + 1];
        }
        // 最後をたす. 極小でも, 引いた分を足す
        res += pol[n - 1];
        cout << res << '\n';
    }

    return 0;
}


// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
void dump_func()
{
    cerr << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&h, Tail &&... t)
{
    cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...);
}
#define dump(...)                                                                                \
    cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), \
        cerr << "*/\n\n";
typedef long long ll;

bool implies(bool b1, bool b2)
{
    return !b1 || b2;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt, n, q;
    cin >> tt;
    while (tt--) {
        cin >> n >> q;
        vector<ll> a(n);
        ll prev = 0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }

        vector<ll> pol;
        for (int i = 0; i < n; i++) {
            // minimal, maximal
            if (implies(0 < i - 1, a[i - 1] < a[i]) && implies(i + 1 < n, a[i + 1] < a[i])) {
                pol.push_back(a[i]);
            }
            else if (implies(0 < i - 1, a[i] < a[i - 1]) && implies(i + 1 < n, a[i] < a[i + 1])) {
                pol.push_back(a[i]);
            }
        }
        ll res = 0;
        int m = pol.size();
        for (int i = 0; i < m - 1; i++) {
            if (pol[i] - pol[i + 1] > 0)
                res += pol[i] - pol[i + 1];
        }
        // 最後をたす. 極小でも, 引いた分を足す
        res += pol[n - 1];
        cout << res << '\n';
    }

    return 0;
}


// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
void dump_func()
{
    cerr << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&h, Tail &&... t)
{
    cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...);
}
#define dump(...)                                                                                \
    cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), \
        cerr << "*/\n\n";
typedef long long ll;

vector<ll> memo(90000, 0);

ll fib(ll n)
{
    if (memo[n] != 0) {
        return memo[n];
    }
    if (n < 2) {
        memo[n] = 1;
        return memo[n];
    }
    else {
        memo[n] = fib(n - 1) + fib(n - 2);
        return memo[n];
    }
}

ll fib_n(ll n)
{
    if (n < 2) {
        return 1;
    }
    else {
        return fib_n(n - 1) + fib_n(n - 2);
    }
}

bool implies(bool b1, bool b2)
{
    return !b1 || b2;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt, n, q;
    cin >> tt;
    while (tt--) {
        cin >> n >> q;
        vector<ll> a(n);
        bool inc = false;
        ll prev = 0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }

        vector<ll> pol;
        for (int i = 0; i < n; i++) {
            // minimal, maximal
            if (implies(0 <= i - 1, a[i - 1] <= a[i]) && implies(i + 1 <= n, a[i + 1] <= a[i])) {
                pol.push_back(a[i]);
            }
            else if (implies(0 <= i - 1, a[i] <= a[i - 1]) && implies(i + 1 <= n, a[i] < a[i + 1])) {
                pol.push_back(a[i]);
            }
        }
        // for (auto e : pol) {
        //     cout << e << '\n';
        // }
        ll res = 0;
        int n = pol.size();
        // 最初と最後は極値
        assert(n >= 2);
        for (int i = 0; i < n - 1; i++) {
            if (pol[i] - pol[i + 1] > 0)
                res += pol[i] - pol[i + 1];
        }
        // 最後をたす. 極小でも, 引いた分を足す
        res += pol[n - 1];
        cout << res << '\n';
    }

    return 0;
}


// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
void dump_func()
{
    cerr << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&h, Tail &&... t)
{
    cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...);
}
#define dump(...)                                                                                \
    cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), \
        cerr << "*/\n\n";
typedef long long ll;

int sum(int n)
{
    return n * (n + 1) / 2;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    cin >> tt;
    int n, q, res = 0;
    while (tt--) {
        cin >> n >> q;
        vector<int> a(n);
        for (int i = 0; i < n; i++)
            cin >> a[i];
        // [+ = 1, - = 0][i]
        // [i, n);
        vector<vector<int>> dp(2, vector<int>(n + 1, 0));

        for (int i = n - 1; i >= 0; i--) {
            dp[0][i] = max(dp[0][i + 1], dp[1][i + 1] + a[i]);
            dp[1][i] = max(dp[1][i + 1], dp[0][i + 1] - a[i]);
        }

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


// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
void dump_func()
{
    cerr << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&h, Tail &&... t)
{
    cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...);
}
#define dump(...)                                                                                \
    cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), \
        cerr << "*/\n\n";
typedef long long ll;

int sum(int n)
{
    return n * (n + 1) / 2;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    cin >> tt;
    int n, q, res = 0;
    while (tt--) {
        cin >> n >> q;
        vector<int> a(n);
        for (int i = 0; i < n; i++)
            cin >> a[i];
        //
        // [add = 0, minus = 1,][i]
        // [i, n);
        vector<vector<int>> dp(2, vector<int>(n + 1, 0));

        for (int i = n - 1; i >= 0; i--) {
            dp[0][i] = max(dp[0][i + 1], dp[1][i + 1] + a[i]);
            dp[1][i] = max(dp[1][i + 1], dp[0][i + 1] - a[i]);
        }

        cout << max(dp[0][0], dp[1][0]) << endl;
    }
    return 0;
}


// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
void dump_func()
{
    cerr << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&h, Tail &&... t)
{
    cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...);
}
#define dump(...)                                                                                \
    cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), \
        cerr << "*/\n\n";
typedef long long ll;

int sum(int n)
{
    return n * (n + 1) / 2;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    cin >> tt;
    int n, q;
    while (tt--) {
        cin >> n >> q;
        vector<ll> a(n);
        for (int i = 0; i < n; i++)
            cin >> a[i];
        //
        // [add = 0, minus = 1,][i]
        // [i, n);
        vector<vector<ll>> dp(2, vector<ll>(n + 1, 0));

        for (int i = n - 1; i >= 0; i--) {
            dp[0][i] = max(dp[0][i + 1], dp[1][i + 1] + a[i]);
            dp[1][i] = max(dp[1][i + 1], dp[0][i + 1] - a[i]);
        }

        cout << dp[0][i] << endl;
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define int long long
using namespace std;
int dp[300005][2];
int arr[300005];
signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int _;
    cin>>_;
    while(_--){
        memset(dp,0,sizeof dp);
     int n,q;
     cin>>n>>q;
     for(int i=0;i<n;i++){
        cin>>arr[i];

     }
     dp[0][1]=arr[0];
     dp[0][0]=-1e5;
     for(int i=1;i<=n;i++){
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]-arr[i]);
        dp[i][1]=max(dp[i-1][1],max(dp[i-1][0]+arr[i],arr[i]));
      //  dp[i][1]=max(dp[i][1],arr[i]);

     }
     cout<<max(dp[n-1][1],dp[n-1][0])<<endl;
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
int dp[300005][2];
int arr[300005];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int _;
    cin>>_;
    while(_--){
        memset(dp,0,sizeof dp);
     int n,q;
     cin>>n>>q;
     for(int i=1;i<=n;i++){
        cin>>arr[i];
     }
     dp[1][1]=arr[1];
     dp[1][0]=-(1<<31);
     for(int i=2;i<=n;i++){
        dp[i][1]=max(dp[i-1][1],max(dp[i-1][0]+arr[i],arr[i]));
      //  dp[i][1]=max(dp[i][1],arr[i]);
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]-arr[i]);
     }
     cout<<max(dp[n][1],dp[n][0])<<endl;
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
int dp[300005][2];
int arr[300005];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int _;
    cin>>_;
    while(_--){
        memset(dp,0,sizeof dp);
     int n,q;
     cin>>n>>q;
     for(int i=1;i<=n;i++){
        cin>>arr[i];
     }
     dp[0][1]=arr[1];
     dp[0][0]=-(1<<31);
     for(int i=1;i<=n;i++){
        dp[i][1]=max(dp[i-1][1],dp[i-1][0]+arr[i]);
        dp[i][1]=max(dp[i][1],arr[i]);
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]-arr[i]);
     }
     cout<<max(dp[n][1],dp[n][0])<<endl;
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
int dp[300005][2];
int arr[300005];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int _;
    cin>>_;
    while(_--){
        memset(dp,0,sizeof dp);
     int n,q;
     cin>>n>>q;
     for(int i=1;i<=n;i++){
        cin>>arr[i];
     }
     dp[1][1]=arr[1];
     dp[1][0]=-(1<<31);
     for(int i=1;i<=n;i++){
        dp[i][1]=max(dp[i-1][1],max(dp[i-1][0]+arr[i],arr[i]));
      //  dp[i][1]=max(dp[i][1],arr[i]);
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]-arr[i]);
     }
     cout<<max(dp[n][1],dp[n][0])<<endl;
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
int dp[300005][2];
int arr[300005];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int _;
    cin>>_;
    while(_--){
        memset(dp,0,sizeof dp);
     int n,q;
     cin>>n>>q;
     for(int i=1;i<=n;i++){
        cin>>arr[i];
     }
     dp[1][1]=arr[1];
     dp[1][0]=-1e5;
     for(int i=2;i<=n;i++){
        dp[i][1]=max(dp[i-1][1],max(dp[i-1][0]+arr[i],arr[i]));
      //  dp[i][1]=max(dp[i][1],arr[i]);
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]-arr[i]);
     }
     cout<<max(dp[n][1],dp[n][0])<<endl;
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
int dp[300005][2];
int arr[300005];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int _;
    cin>>_;
    while(_--){
        memset(dp,0,sizeof dp);
     int n,q;
     cin>>n>>q;
     for(int i=1;i<=n;i++){
        cin>>arr[i];

     }
     dp[1][1]=arr[1];
     dp[1][0]=-1e5;
     for(int i=2;i<=n+1;i++){
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]-arr[i]);
        dp[i][1]=max(dp[i-1][1],max(dp[i-1][0]+arr[i],arr[i]));
      //  dp[i][1]=max(dp[i][1],arr[i]);

     }
     cout<<max(dp[n+1][1],dp[n+1][0])<<endl;
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
int dp[300005][2];
int arr[300005];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int _;
    cin>>_;
    while(_--){
        memset(dp,0,sizeof dp);
     int n,q;
     cin>>n>>q;
     for(int i=1;i<=n;i++){
        cin>>arr[i];
     }
     dp[0][1]=arr[1];
     dp[0][0]=-(1<<31);
     for(int i=1;i<=n;i++){
        dp[i][1]=max(dp[i-1][1],max(dp[i-1][0]+arr[i],arr[i]));
      //  dp[i][1]=max(dp[i][1],arr[i]);
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]-arr[i]);
     }
     cout<<max(dp[n][1],dp[n][0])<<endl;
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
int dp[300005][2];
int arr[300005];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int _;
    cin>>_;
    while(_--){
        memset(dp,0,sizeof dp);
     int n,q;
     cin>>n>>q;
     for(int i=1;i<=n;i++)cin>>arr[i];
     for(int i=1;i<=n;i++){
        dp[i][1]=max(dp[i-1][1],dp[i-1][0]+arr[i]);
        dp[i][1]=max(dp[i][1],arr[i]);
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]-arr[i]);
     }
     cout<<max(dp[n][1],dp[n][0])<<endl;
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
int dp[300005][2];
int arr[300005];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int _;
    cin>>_;
    while(_--){
        memset(dp,0,sizeof dp);
     int n,q;
     cin>>n>>q;
     for(int i=0;i<n;i++){
        cin>>arr[i];

     }
     dp[0][1]=arr[0];
     dp[0][0]=-1e5;
     for(int i=1;i<=n-1;i++){
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]-arr[i]);
        dp[i][1]=max(dp[i-1][1],max(dp[i-1][0]+arr[i],arr[i]));
      //  dp[i][1]=max(dp[i][1],arr[i]);

     }
     cout<<max(dp[n-1][1],dp[n-1][0])<<endl;
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#define int long long
#include<bits/stdc++.h>
using namespace std;
int dp[300005][2];
int arr[300005];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int _;
    cin>>_;
    while(_--){
        memset(dp,0,sizeof dp);
     int n,q;
     cin>>n>>q;
     for(int i=0;i<n;i++){
        cin>>arr[i];

     }
     dp[0][1]=arr[0];
     dp[0][0]=-1e5;
     for(int i=1;i<=n;i++){
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]-arr[i]);
        dp[i][1]=max(dp[i-1][1],max(dp[i-1][0]+arr[i],arr[i]));
      //  dp[i][1]=max(dp[i][1],arr[i]);

     }
     cout<<max(dp[n-1][1],dp[n-1][0])<<endl;
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define int long long
using namespace std;
int dp[300005][2];
int arr[300005];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int _;
    cin>>_;
    while(_--){
        memset(dp,0,sizeof dp);
     int n,q;
     cin>>n>>q;
     for(int i=0;i<n;i++){
        cin>>arr[i];

     }
     dp[0][1]=arr[0];
     dp[0][0]=-1e5;
     for(int i=1;i<=n;i++){
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]-arr[i]);
        dp[i][1]=max(dp[i-1][1],max(dp[i-1][0]+arr[i],arr[i]));
      //  dp[i][1]=max(dp[i][1],arr[i]);

     }
     cout<<max(dp[n-1][1],dp[n-1][0])<<endl;
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
int dp[300005][2];
int arr[300005];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int _;
    cin>>_;
    while(_--){
        memset(dp,0,sizeof dp);
     int n,q;
     cin>>n>>q;
     for(int i=1;i<=n;i++){
        cin>>arr[i];
     }
     dp[0][1]=arr[1];
     dp[0][0]=-(1<<31);
     for(int i=1;i<=n;i++){
        dp[i][1]=max(dp[i-1][1],max(dp[i-1][0]+arr[i],arr[i]);
      //  dp[i][1]=max(dp[i][1],arr[i]);
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]-arr[i]);
     }
     cout<<max(dp[n][1],dp[n][0])<<endl;
    }
}


//белый снег
//белый porshe
//белый trash
//в бонге воск
#include <iostream>
#include <locale>
#include <string>
#include <iomanip>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <vector>
#include <stdlib.h>
#include <clocale>
#include <algorithm>
#include <iterator>
#include <list>
#include <set>
#include <cstddef>
#include <cstdio>
#include <stdio.h>
#include <map>
#include <cmath>
#include <functional>
#include <stack>
#include <type_traits>
#include <queue>
#include <memory>
#include <memory.h>
#include <time.h>
#include <ctime>
#pragma warning(disable:4996)
using namespace std;
#define Kirja_ES ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define pf push_front
#define irt insert
#define ll long long
#define int long long
#define ull unsigned long long
#define str string
#define vi vector<int>
#define vll vector<ll>
#define si set<int>
#define sll set<ll>
#define msi multiset<int>
#define msll multiset<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define left false
#define right true
int n, q, in1[300013] = {};
vector<vll> tree_v(1200013, vll(4)); //четное макс/мин нечетное макс/мин
vll build(int v, int left_tec, int right_tec)
{
	if (left_tec + 1 == right_tec)
	{
		tree_v[v][0] = 0;
		tree_v[v][1] = 0;
		tree_v[v][2] = in1[left_tec];
		tree_v[v][3] = in1[left_tec];
		return tree_v[v];
	}
	auto left_q = build(2 * v + 1, left_tec, (left_tec + right_tec) / 2);
	auto right_q = build(2 * v + 2, (left_tec + right_tec) / 2, right_tec);
	tree_v[v][0] = 0;
	tree_v[v][0] = 0;
	tree_v[v][2] = -1e16;
	tree_v[v][3] = 1e16;
	tree_v[v][0] = max(tree_v[v][0], max(left_q[0], right_q[0]));
	tree_v[v][0] = max(tree_v[v][0], left_q[0] + right_q[0]);
	tree_v[v][0] = max(tree_v[v][0], left_q[2] + right_q[2]);
	tree_v[v][0] = max(tree_v[v][0], left_q[2] - right_q[3]);

	tree_v[v][1] = min(tree_v[v][1], min(left_q[1], right_q[1]));
	tree_v[v][1] = min(tree_v[v][1], left_q[1] + right_q[1]);
	tree_v[v][1] = min(tree_v[v][1], left_q[3] - right_q[2]);
	//четное макс/мин нечетное макс/мин
	tree_v[v][2] = max(tree_v[v][2], max(left_q[2], right_q[2]));
	tree_v[v][2] = max(tree_v[v][2], left_q[0] + right_q[2]);
	tree_v[v][2] = max(tree_v[v][2], left_q[2] - right_q[1]);

	tree_v[v][3] = min(tree_v[v][3], min(left_q[3], right_q[3]));
	tree_v[v][3] = min(tree_v[v][3], left_q[1] + right_q[3]);
	tree_v[v][3] = min(tree_v[v][3], left_q[3] - right_q[0]);

	return tree_v[v];
}

vll update_t(int v, int left_tec, int right_tec, int index)
{
	if (left_tec + 1 == right_tec && left_tec == index)
	{
		tree_v[v][0] = 0;
		tree_v[v][1] = 0;
		tree_v[v][2] = in1[left_tec];
		tree_v[v][3] = in1[left_tec];
		return tree_v[v];
	}
	auto left_q = tree_v[2 * v + 1], right_q = tree_v[2 * v + 2];
	if (left_tec <= index && index < (left_tec + right_tec) / 2)
		left_q = update_t(2 * v + 1, left_tec, (left_tec + right_tec) / 2, index);
	if ((left_tec + right_tec) / 2 <= index && index < right_tec)
		right_q = update_t(2 * v + 2, (left_tec + right_tec) / 2, right_tec, index);
	tree_v[v][0] = 0;
	tree_v[v][0] = 0;
	tree_v[v][2] = -1e16;
	tree_v[v][3] = 1e16;

	//tree_v[v][0] = max(tree_v[v][0], max(left_q[0], right_q[0]));
	tree_v[v][0] = max(tree_v[v][0], left_q[0] + right_q[0]);
	tree_v[v][0] = max(tree_v[v][0], left_q[2] - right_q[3]);

	//tree_v[v][1] = min(tree_v[v][1], min(left_q[1], right_q[1]));
	tree_v[v][1] = min(tree_v[v][1], left_q[1] + right_q[1]);
	tree_v[v][1] = min(tree_v[v][1], left_q[3] - right_q[2]);

	//четное макс/мин нечетное макс/мин
	//tree_v[v][2] = max(tree_v[v][2], max(left_q[2], right_q[2]));
	tree_v[v][2] = max(tree_v[v][2], left_q[0] + right_q[2]);
	tree_v[v][2] = max(tree_v[v][2], left_q[2] - right_q[1]);

	//tree_v[v][3] = min(tree_v[v][3], min(left_q[3], right_q[3]));
	tree_v[v][3] = min(tree_v[v][3], left_q[1] + right_q[3]);
	tree_v[v][3] = min(tree_v[v][3], left_q[3] - right_q[0]);

	return tree_v[v];
}

signed main()
{
	Kirja_ES;
		freopen("input.in", "r", stdin);
	//	freopen("output.out", "w", stdout);
	int t;
	cin >> t;
	while (t--)
	{
		cin >> n >> q;
		for (int i = 0; i < n; ++i)
		{
			int h;
			cin >> h;
			in1[i] = h;
		}
		build(0, 0, n);
		cout << max(tree_v[0][2], tree_v[0][0]) << "\n";
		while (q--)
		{
			int l, r;
			cin >> l >> r;
			l--, r--;
			swap(in1[l], in1[r]);
			update_t(0, 0, n, l);
			update_t(0, 0, n, r);
			cout << tree_v[0][2] << "\n";
		}
	}
	return 0;
}


//белый снег
//белый porshe
//белый trash
//в бонге воск
#include <iostream>
#include <locale>
#include <string>
#include <iomanip>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <vector>
#include <stdlib.h>
#include <clocale>
#include <algorithm>
#include <iterator>
#include <list>
#include <set>
#include <cstddef>
#include <cstdio>
#include <stdio.h>
#include <map>
#include <cmath>
#include <functional>
#include <stack>
#include <type_traits>
#include <queue>
#include <memory>
#include <memory.h>
#include <time.h>
#include <ctime>
#pragma warning(disable:4996)
using namespace std;
#define Kirja_ES ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define pf push_front
#define irt insert
#define ll long long
#define int long long
#define ull unsigned long long
#define str string
#define vi vector<int>
#define vll vector<ll>
#define si set<int>
#define sll set<ll>
#define msi multiset<int>
#define msll multiset<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define left false
#define right true
int n, q, in1[300013] = {};
vector<vll> tree_v(1200013, vll(4)); //четное макс/мин нечетное макс/мин
vll build(int v, int left_tec, int right_tec)
{
	if (left_tec + 1 == right_tec)
	{
		tree_v[v][0] = 0;
		tree_v[v][1] = 0;
		tree_v[v][2] = in1[left_tec];
		tree_v[v][3] = in1[left_tec];
		return tree_v[v];
	}
	auto left_q = build(2 * v + 1, left_tec, (left_tec + right_tec) / 2);
	auto right_q = build(2 * v + 2, (left_tec + right_tec) / 2, right_tec);
	tree_v[v][0] = 0;
	tree_v[v][0] = 0;
	tree_v[v][2] = -1e16;
	tree_v[v][3] = 1e16;
	tree_v[v][0] = max(tree_v[v][0], max(left_q[0], right_q[0]));
	tree_v[v][0] = max(tree_v[v][0], left_q[0] + right_q[0]);
	tree_v[v][0] = max(tree_v[v][0], left_q[2] - right_q[3]);

	tree_v[v][1] = min(tree_v[v][1], min(left_q[1], right_q[1]));
	tree_v[v][1] = min(tree_v[v][1], left_q[1] + right_q[1]);
	tree_v[v][1] = min(tree_v[v][1], left_q[3] - right_q[2]);
	//четное макс/мин нечетное макс/мин
	tree_v[v][2] = max(tree_v[v][2], max(left_q[2], right_q[2]));
	tree_v[v][2] = max(tree_v[v][2], left_q[0] + right_q[2]);
	tree_v[v][2] = max(tree_v[v][2], left_q[2] - right_q[1]);

	tree_v[v][3] = min(tree_v[v][3], min(left_q[3], right_q[3]));
	tree_v[v][3] = min(tree_v[v][3], left_q[1] + right_q[3]);
	tree_v[v][3] = min(tree_v[v][3], left_q[3] - right_q[0]);

	return tree_v[v];
}

vll update_t(int v, int left_tec, int right_tec, int index)
{
	if (left_tec + 1 == right_tec && left_tec == index)
	{
		tree_v[v][0] = 0;
		tree_v[v][1] = 0;
		tree_v[v][2] = in1[left_tec];
		tree_v[v][3] = in1[left_tec];
		return tree_v[v];
	}
	auto left_q = tree_v[2 * v + 1], right_q = tree_v[2 * v + 2];
	if (left_tec <= index && index < (left_tec + right_tec) / 2)
		left_q = update_t(2 * v + 1, left_tec, (left_tec + right_tec) / 2, index);
	if ((left_tec + right_tec) / 2 <= index && index < right_tec)
		right_q = update_t(2 * v + 2, (left_tec + right_tec) / 2, right_tec, index);
	tree_v[v][0] = 0;
	tree_v[v][0] = 0;
	tree_v[v][2] = -1e16;
	tree_v[v][3] = 1e16;

	tree_v[v][0] = max(tree_v[v][0], max(left_q[0], right_q[0]));
	tree_v[v][0] = max(tree_v[v][0], left_q[0] + right_q[0]);
	tree_v[v][0] = max(tree_v[v][0], left_q[2] - right_q[3]);

	tree_v[v][1] = min(tree_v[v][1], min(left_q[1], right_q[1]));
	tree_v[v][1] = min(tree_v[v][1], left_q[1] + right_q[1]);
	tree_v[v][1] = min(tree_v[v][1], left_q[3] - right_q[2]);

	//четное макс/мин нечетное макс/мин
	tree_v[v][2] = max(tree_v[v][2], max(left_q[2], right_q[2]));
	tree_v[v][2] = max(tree_v[v][2], left_q[0] + right_q[2]);
	tree_v[v][2] = max(tree_v[v][2], left_q[2] - right_q[1]);

	tree_v[v][3] = min(tree_v[v][3], min(left_q[3], right_q[3]));
	tree_v[v][3] = min(tree_v[v][3], left_q[1] + right_q[3]);
	tree_v[v][3] = min(tree_v[v][3], left_q[3] - right_q[0]);

	return tree_v[v];
}

signed main()
{
	Kirja_ES;
		freopen("input.in", "r", stdin);
	//	freopen("output.out", "w", stdout);
	int t;
	cin >> t;
	while (t--)
	{
		cin >> n >> q;
		for (int i = 0; i < n; ++i)
		{
			int h;
			cin >> h;
			in1[i] = h;
		}
		build(0, 0, n);
		cout << max(tree_v[0][2], tree_v[0][0]) << "\n";
		while (q--)
		{
			int l, r;
			cin >> l >> r;
			l--, r--;
			swap(in1[l], in1[r]);
			update_t(0, 0, n, l);
			update_t(0, 0, n, r);
			cout << tree_v[0][2] << "\n";
		}
	}
	return 0;
}


//белый снег
//белый porshe
//белый trash
//в бонге воск
#include <iostream>
#include <locale>
#include <string>
#include <iomanip>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <vector>
#include <stdlib.h>
#include <clocale>
#include <algorithm>
#include <iterator>
#include <list>
#include <set>
#include <cstddef>
#include <cstdio>
#include <stdio.h>
#include <map>
#include <cmath>
#include <functional>
#include <stack>
#include <type_traits>
#include <queue>
#include <memory>
#include <memory.h>
#include <time.h>
#include <ctime>
#pragma warning(disable:4996)
using namespace std;
#define Kirja_ES ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define pf push_front
#define irt insert
#define ll long long
#define int long long
#define ull unsigned long long
#define str string
#define vi vector<int>
#define vll vector<ll>
#define si set<int>
#define sll set<ll>
#define msi multiset<int>
#define msll multiset<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define left false
#define right true
int n, q, in1[300013] = {};
vector<vll> tree_v(1200013, vll(4)); //четное макс/мин нечетное макс/мин
vll build(int v, int left_tec, int right_tec)
{
	if (left_tec + 1 == right_tec)
	{
		tree_v[v][0] = 0;
		tree_v[v][1] = 0;
		tree_v[v][2] = in1[left_tec];
		tree_v[v][3] = in1[left_tec];
		return tree_v[v];
	}
	auto left_q = build(2 * v + 1, left_tec, (left_tec + right_tec) / 2);
	auto right_q = build(2 * v + 2, (left_tec + right_tec) / 2, right_tec);
	tree_v[v][0] = 0;
	tree_v[v][0] = 0;
	tree_v[v][2] = -1e16;
	tree_v[v][3] = 1e16;
	tree_v[v][0] = max(tree_v[v][0], max(left_q[0], right_q[0]));
	tree_v[v][0] = max(tree_v[v][0], left_q[0] + right_q[0]);
	tree_v[v][0] = max(tree_v[v][0], left_q[2] - right_q[3]);

	tree_v[v][1] = min(tree_v[v][1], min(left_q[1], right_q[1]));
	tree_v[v][1] = min(tree_v[v][1], left_q[1] + right_q[1]);
	tree_v[v][1] = min(tree_v[v][1], left_q[3] - right_q[2]);
	//четное макс/мин нечетное макс/мин
	tree_v[v][2] = max(tree_v[v][2], max(left_q[2], right_q[2]));
	tree_v[v][2] = max(tree_v[v][2], left_q[0] + right_q[2]);
	tree_v[v][2] = max(tree_v[v][2], left_q[2] - right_q[1]);

	tree_v[v][3] = min(tree_v[v][3], min(left_q[3], right_q[3]));
	tree_v[v][3] = min(tree_v[v][3], left_q[1] + right_q[3]);
	tree_v[v][3] = min(tree_v[v][3], left_q[3] - right_q[0]);

	return tree_v[v];
}

vll update_t(int v, int left_tec, int right_tec, int index)
{
	if (left_tec + 1 == right_tec && left_tec == index)
	{
		tree_v[v][0] = 0;
		tree_v[v][1] = 0;
		tree_v[v][2] = in1[left_tec];
		tree_v[v][3] = in1[left_tec];
		return tree_v[v];
	}
	auto left_q = tree_v[2 * v + 1], right_q = tree_v[2 * v + 2];
	if (left_tec <= index && index < (left_tec + right_tec) / 2)
		left_q = update_t(2 * v + 1, left_tec, (left_tec + right_tec) / 2, index);
	if ((left_tec + right_tec) / 2 <= index && index < right_tec)
		right_q = update_t(2 * v + 2, (left_tec + right_tec) / 2, right_tec, index);
	tree_v[v][0] = 0;
	tree_v[v][0] = 0;
	tree_v[v][2] = -1e16;
	tree_v[v][3] = 1e16;

	//tree_v[v][0] = max(tree_v[v][0], max(left_q[0], right_q[0]));
	tree_v[v][0] = max(tree_v[v][0], left_q[0] + right_q[0]);
	tree_v[v][0] = max(tree_v[v][0], left_q[2] - right_q[3]);

	//tree_v[v][1] = min(tree_v[v][1], min(left_q[1], right_q[1]));
	tree_v[v][1] = min(tree_v[v][1], left_q[1] + right_q[1]);
	tree_v[v][1] = min(tree_v[v][1], left_q[3] - right_q[2]);

	//четное макс/мин нечетное макс/мин
	//tree_v[v][2] = max(tree_v[v][2], max(left_q[2], right_q[2]));
	tree_v[v][2] = max(tree_v[v][2], left_q[0] + right_q[2]);
	tree_v[v][2] = max(tree_v[v][2], left_q[2] - right_q[1]);

	//tree_v[v][3] = min(tree_v[v][3], min(left_q[3], right_q[3]));
	tree_v[v][3] = min(tree_v[v][3], left_q[1] + right_q[3]);
	tree_v[v][3] = min(tree_v[v][3], left_q[3] - right_q[0]);

	return tree_v[v];
}

signed main()
{
	Kirja_ES;
		freopen("input.in", "r", stdin);
	//	freopen("output.out", "w", stdout);
	int t;
	cin >> t;
	while (t--)
	{
		cin >> n >> q;
		for (int i = 0; i < n; ++i)
		{
			int h;
			cin >> h;
			in1[i] = h;
		}
		build(0, 0, n);
		cout << max(tree_v[0][2], tree_v[0][0]) << "\n";
		while (q--)
		{
			int l, r;
			cin >> l >> r;
			l--, r--;
			swap(in1[l], in1[r]);
			update_t(0, 0, n, l);
			update_t(0, 0, n, r);
			cout << tree_v[0][2] << "\n";
		}
	}
	return 0;
}


//белый снег
//белый porshe
//белый trash
//в бонге воск
#include <iostream>
#include <locale>
#include <string>
#include <iomanip>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <vector>
#include <stdlib.h>
#include <clocale>
#include <algorithm>
#include <iterator>
#include <list>
#include <set>
#include <cstddef>
#include <cstdio>
#include <stdio.h>
#include <map>
#include <cmath>
#include <functional>
#include <stack>
#include <type_traits>
#include <queue>
#include <memory>
#include <memory.h>
#include <time.h>
#include <ctime>
#pragma warning(disable:4996)
using namespace std;
#define Kirja_ES ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define pf push_front
#define irt insert
#define ll long long
#define int long long
#define ull unsigned long long
#define str string
#define vi vector<int>
#define vll vector<ll>
#define si set<int>
#define sll set<ll>
#define msi multiset<int>
#define msll multiset<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define left false
#define right true
int n, q, in1[300013] = {};
vector<vll> tree_v(1200013, vll(4)); //четное макс/мин нечетное макс/мин
vll build(int v, int left_tec, int right_tec)
{
	if (left_tec + 1 == right_tec)
	{
		tree_v[v][0] = 0;
		tree_v[v][1] = 0;
		tree_v[v][2] = in1[left_tec];
		tree_v[v][3] = in1[left_tec];
		return tree_v[v];
	}
	auto left_q  = build(2 * v + 1, left_tec, (left_tec + right_tec) / 2);
	auto right_q = build(2 * v + 2, (left_tec + right_tec) / 2, right_tec);
	tree_v[v][0] = 0;
	tree_v[v][0] = 0;
	tree_v[v][2] = -1e9;
	tree_v[v][3] = 1e9;
	tree_v[v][0] = max(tree_v[v][0], max(left_q[0], right_q[0]));
	tree_v[v][0] = max(tree_v[v][0], left_q[0] + right_q[0]);
	tree_v[v][0] = max(tree_v[v][0], left_q[2] - right_q[3]);

	tree_v[v][1] = min(tree_v[v][1], min(left_q[1], right_q[1]));
	tree_v[v][1] = min(tree_v[v][1], left_q[1] + right_q[1]);
	tree_v[v][1] = min(tree_v[v][1], left_q[3] - right_q[2]);
	//четное макс/мин нечетное макс/мин
	tree_v[v][2] = max(tree_v[v][2], max(left_q[2], right_q[2]));
	tree_v[v][2] = max(tree_v[v][2], left_q[0] + right_q[2]);
	tree_v[v][2] = max(tree_v[v][2], left_q[2] - right_q[1]);

	tree_v[v][3] = min(tree_v[v][3], min(left_q[3], right_q[3]));
	tree_v[v][3] = min(tree_v[v][3], left_q[1] + right_q[3]);
	tree_v[v][3] = min(tree_v[v][3], left_q[3] - right_q[0]);

	return tree_v[v];
}

vll update_t(int v, int left_tec, int right_tec, int index)
{
	if (left_tec + 1 == right_tec && left_tec == index)
	{
		tree_v[v][0] = 0;
		tree_v[v][1] = 0;
		tree_v[v][2] = in1[left_tec];
		tree_v[v][3] = in1[left_tec];
		return tree_v[v];
	}
	auto left_q = tree_v[2 * v + 1], right_q = tree_v[2 * v + 2];
	if(left_tec <= index && index < (left_tec+right_tec)/2)
		left_q = update_t(2 * v + 1, left_tec, (left_tec + right_tec) / 2, index);
	if((left_tec+right_tec)/2 <= index && index < right_tec)
		right_q = update_t(2 * v + 2, (left_tec + right_tec) / 2, right_tec, index);
	tree_v[v][0] = 0;
	tree_v[v][0] = 0;
	tree_v[v][2] = -1e9;
	tree_v[v][3] = 1e9;

	tree_v[v][0] = max(tree_v[v][0], max(left_q[0], right_q[0]));
	tree_v[v][0] = max(tree_v[v][0], left_q[0] + right_q[0]);
	tree_v[v][0] = max(tree_v[v][0], left_q[2] - right_q[3]);

	tree_v[v][1] = min(tree_v[v][1], min(left_q[1], right_q[1]));
	tree_v[v][1] = min(tree_v[v][1], left_q[1] + right_q[1]);
	tree_v[v][1] = min(tree_v[v][1], left_q[3] - right_q[2]);

	//четное макс/мин нечетное макс/мин
	tree_v[v][2] = max(tree_v[v][2], max(left_q[2], right_q[2]));
	tree_v[v][2] = max(tree_v[v][2], left_q[0] + right_q[2]);
	tree_v[v][2] = max(tree_v[v][2], left_q[2] - right_q[1]);

	tree_v[v][3] = min(tree_v[v][3], min(left_q[3], right_q[3]));
	tree_v[v][3] = min(tree_v[v][3], left_q[1] + right_q[3]);
	tree_v[v][3] = min(tree_v[v][3], left_q[3] - right_q[0]);

	return tree_v[v];
}

signed main()
{
	Kirja_ES;
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
	int t;
	cin >> t;
	while (t--)
	{
		cin >> n >> q;
		for (int i = 0; i < n; ++i)
		{
			int h;
			cin >> h;
			in1[i] = h;
		}
		build(0, 0, n);
		cout << tree_v[0][2] << "\n";
		while (q--)
		{
			int l, r;
			cin >> l >> r;
			l--, r--;
			swap(in1[l], in1[r]);
			update_t(0, 0, n, l);
			update_t(0, 0, n, r);
			cout << tree_v[0][2] << "\n";
		}
	}
	return 0;
}


//белый снег
//белый porshe
//белый trash
//в бонге воск
#include <iostream>
#include <locale>
#include <string>
#include <iomanip>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <vector>
#include <stdlib.h>
#include <clocale>
#include <algorithm>
#include <iterator>
#include <list>
#include <set>
#include <cstddef>
#include <cstdio>
#include <stdio.h>
#include <map>
#include <cmath>
#include <functional>
#include <stack>
#include <type_traits>
#include <queue>
#include <memory>
#include <memory.h>
#include <time.h>
#include <ctime>
#pragma warning(disable:4996)
using namespace std;
#define Kirja_ES ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define pf push_front
#define irt insert
#define ll long long
#define int long long
#define ull unsigned long long
#define str string
#define vi vector<int>
#define vll vector<ll>
#define si set<int>
#define sll set<ll>
#define msi multiset<int>
#define msll multiset<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define left false
#define right true
int n, q, in1[300013] = {};
vector<vll> tree_v(1200013, vll(4)); //четное макс/мин нечетное макс/мин
vll build(int v, int left_tec, int right_tec)
{
	if (left_tec + 1 == right_tec)
	{
		tree_v[v][0] = 0;
		tree_v[v][1] = 0;
		tree_v[v][2] = in1[left_tec];
		tree_v[v][3] = in1[left_tec];
		return tree_v[v];
	}
	auto left_q = build(2 * v + 1, left_tec, (left_tec + right_tec) / 2);
	auto right_q = build(2 * v + 2, (left_tec + right_tec) / 2, right_tec);
	tree_v[v][0] = 0;
	tree_v[v][0] = 0;
	tree_v[v][2] = -1e16;
	tree_v[v][3] = 1e16;
	tree_v[v][0] = max(tree_v[v][0], max(left_q[0], right_q[0]));
	tree_v[v][0] = max(tree_v[v][0], left_q[0] + right_q[0]);
	tree_v[v][0] = max(tree_v[v][0], left_q[2] - right_q[3]);

	tree_v[v][1] = min(tree_v[v][1], min(left_q[1], right_q[1]));
	tree_v[v][1] = min(tree_v[v][1], left_q[1] + right_q[1]);
	tree_v[v][1] = min(tree_v[v][1], left_q[3] - right_q[2]);
	//четное макс/мин нечетное макс/мин
	tree_v[v][2] = max(tree_v[v][2], max(left_q[2], right_q[2]));
	tree_v[v][2] = max(tree_v[v][2], left_q[0] + right_q[2]);
	tree_v[v][2] = max(tree_v[v][2], left_q[2] - right_q[1]);

	tree_v[v][3] = min(tree_v[v][3], min(left_q[3], right_q[3]));
	tree_v[v][3] = min(tree_v[v][3], left_q[1] + right_q[3]);
	tree_v[v][3] = min(tree_v[v][3], left_q[3] - right_q[0]);

	return tree_v[v];
}

vll update_t(int v, int left_tec, int right_tec, int index)
{
	if (left_tec + 1 == right_tec && left_tec == index)
	{
		tree_v[v][0] = 0;
		tree_v[v][1] = 0;
		tree_v[v][2] = in1[left_tec];
		tree_v[v][3] = in1[left_tec];
		return tree_v[v];
	}
	auto left_q = tree_v[2 * v + 1], right_q = tree_v[2 * v + 2];
	if (left_tec <= index && index < (left_tec + right_tec) / 2)
		left_q = update_t(2 * v + 1, left_tec, (left_tec + right_tec) / 2, index);
	if ((left_tec + right_tec) / 2 <= index && index < right_tec)
		right_q = update_t(2 * v + 2, (left_tec + right_tec) / 2, right_tec, index);
	tree_v[v][0] = 0;
	tree_v[v][0] = 0;
	tree_v[v][2] = -1e16;
	tree_v[v][3] = 1e16;

	tree_v[v][0] = max(tree_v[v][0], max(left_q[0], right_q[0]));
	tree_v[v][0] = max(tree_v[v][0], left_q[0] + right_q[0]);
	tree_v[v][0] = max(tree_v[v][0], left_q[2] - right_q[3]);

	tree_v[v][1] = min(tree_v[v][1], min(left_q[1], right_q[1]));
	tree_v[v][1] = min(tree_v[v][1], left_q[1] + right_q[1]);
	tree_v[v][1] = min(tree_v[v][1], left_q[3] - right_q[2]);

	//четное макс/мин нечетное макс/мин
	tree_v[v][2] = max(tree_v[v][2], max(left_q[2], right_q[2]));
	tree_v[v][2] = max(tree_v[v][2], left_q[0] + right_q[2]);
	tree_v[v][2] = max(tree_v[v][2], left_q[2] - right_q[1]);

	tree_v[v][3] = min(tree_v[v][3], min(left_q[3], right_q[3]));
	tree_v[v][3] = min(tree_v[v][3], left_q[1] + right_q[3]);
	tree_v[v][3] = min(tree_v[v][3], left_q[3] - right_q[0]);

	return tree_v[v];
}

signed main()
{
	Kirja_ES;
	//	freopen("input.in", "r", stdin);
	//	freopen("output.out", "w", stdout);
	int t;
	cin >> t;
	while (t--)
	{
		cin >> n >> q;
		for (int i = 0; i < n; ++i)
		{
			int h;
			cin >> h;
			in1[i] = h;
		}
		build(0, 0, n);
		cout << max(tree_v[0][2], tree_v[0][0]) << "\n";
		while (q--)
		{
			int l, r;
			cin >> l >> r;
			l--, r--;
			swap(in1[l], in1[r]);
			update_t(0, 0, n, l);
			update_t(0, 0, n, r);
			cout << tree_v[0][2] << "\n";
		}
	}
	return 0;
}


//белый снег
//белый porshe
//белый trash
//в бонге воск
#include <iostream>
#include <locale>
#include <string>
#include <iomanip>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <vector>
#include <stdlib.h>
#include <clocale>
#include <algorithm>
#include <iterator>
#include <list>
#include <set>
#include <cstddef>
#include <cstdio>
#include <stdio.h>
#include <map>
#include <cmath>
#include <functional>
#include <stack>
#include <type_traits>
#include <queue>
#include <memory>
#include <memory.h>
#include <time.h>
#include <ctime>
#pragma warning(disable:4996)
using namespace std;
#define Kirja_ES ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define pf push_front
#define irt insert
#define ll long long
#define int long long
#define ull unsigned long long
#define str string
#define vi vector<int>
#define vll vector<ll>
#define si set<int>
#define sll set<ll>
#define msi multiset<int>
#define msll multiset<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define left false
#define right true
int n, q, in1[300013] = {};
vector<vll> tree_v(1200013, vll(4)); //четное макс/мин нечетное макс/мин
vll build(int v, int left_tec, int right_tec)
{
	if (left_tec + 1 == right_tec)
	{
		tree_v[v][0] = 0;
		tree_v[v][1] = 0;
		tree_v[v][2] = in1[left_tec];
		tree_v[v][3] = in1[left_tec];
		return tree_v[v];
	}
	auto left_q  = build(2 * v + 1, left_tec, (left_tec + right_tec) / 2);
	auto right_q = build(2 * v + 2, (left_tec + right_tec) / 2, right_tec);
	tree_v[v][0] = 0;
	tree_v[v][0] = 0;
	tree_v[v][2] = -1e16;
	tree_v[v][3] = 1e16;
	tree_v[v][0] = max(tree_v[v][0], max(left_q[0], right_q[0]));
	tree_v[v][0] = max(tree_v[v][0], left_q[0] + right_q[0]);
	tree_v[v][0] = max(tree_v[v][0], left_q[2] - right_q[3]);

	tree_v[v][1] = min(tree_v[v][1], min(left_q[1], right_q[1]));
	tree_v[v][1] = min(tree_v[v][1], left_q[1] + right_q[1]);
	tree_v[v][1] = min(tree_v[v][1], left_q[3] - right_q[2]);
	//четное макс/мин нечетное макс/мин
	tree_v[v][2] = max(tree_v[v][2], max(left_q[2], right_q[2]));
	tree_v[v][2] = max(tree_v[v][2], left_q[0] + right_q[2]);
	tree_v[v][2] = max(tree_v[v][2], left_q[2] - right_q[1]);

	tree_v[v][3] = min(tree_v[v][3], min(left_q[3], right_q[3]));
	tree_v[v][3] = min(tree_v[v][3], left_q[1] + right_q[3]);
	tree_v[v][3] = min(tree_v[v][3], left_q[3] - right_q[0]);

	return tree_v[v];
}

vll update_t(int v, int left_tec, int right_tec, int index)
{
	if (left_tec + 1 == right_tec && left_tec == index)
	{
		tree_v[v][0] = 0;
		tree_v[v][1] = 0;
		tree_v[v][2] = in1[left_tec];
		tree_v[v][3] = in1[left_tec];
		return tree_v[v];
	}
	auto left_q = tree_v[2 * v + 1], right_q = tree_v[2 * v + 2];
	if(left_tec <= index && index < (left_tec+right_tec)/2)
		left_q = update_t(2 * v + 1, left_tec, (left_tec + right_tec) / 2, index);
	if((left_tec+right_tec)/2 <= index && index < right_tec)
		right_q = update_t(2 * v + 2, (left_tec + right_tec) / 2, right_tec, index);
	tree_v[v][0] = 0;
	tree_v[v][0] = 0;
	tree_v[v][2] = -1e16;
	tree_v[v][3] = 1e16;

	tree_v[v][0] = max(tree_v[v][0], max(left_q[0], right_q[0]));
	tree_v[v][0] = max(tree_v[v][0], left_q[0] + right_q[0]);
	tree_v[v][0] = max(tree_v[v][0], left_q[2] - right_q[3]);

	tree_v[v][1] = min(tree_v[v][1], min(left_q[1], right_q[1]));
	tree_v[v][1] = min(tree_v[v][1], left_q[1] + right_q[1]);
	tree_v[v][1] = min(tree_v[v][1], left_q[3] - right_q[2]);

	//четное макс/мин нечетное макс/мин
	tree_v[v][2] = max(tree_v[v][2], max(left_q[2], right_q[2]));
	tree_v[v][2] = max(tree_v[v][2], left_q[0] + right_q[2]);
	tree_v[v][2] = max(tree_v[v][2], left_q[2] - right_q[1]);

	tree_v[v][3] = min(tree_v[v][3], min(left_q[3], right_q[3]));
	tree_v[v][3] = min(tree_v[v][3], left_q[1] + right_q[3]);
	tree_v[v][3] = min(tree_v[v][3], left_q[3] - right_q[0]);

	return tree_v[v];
}

signed main()
{
	Kirja_ES;
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
	int t;
	cin >> t;
	while (t--)
	{
		cin >> n >> q;
		for (int i = 0; i < n; ++i)
		{
			int h;
			cin >> h;
			in1[i] = h;
		}
		build(0, 0, n);
		cout << tree_v[0][2] << "\n";
		while (q--)
		{
			int l, r;
			cin >> l >> r;
			l--, r--;
			swap(in1[l], in1[r]);
			update_t(0, 0, n, l);
			update_t(0, 0, n, r);
			cout << tree_v[0][2] << "\n";
		}
	}
	return 0;
}


//белый снег
//белый porshe
//белый trash
//в бонге воск
#include <iostream>
#include <locale>
#include <string>
#include <iomanip>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <vector>
#include <stdlib.h>
#include <clocale>
#include <algorithm>
#include <iterator>
#include <list>
#include <set>
#include <cstddef>
#include <cstdio>
#include <stdio.h>
#include <map>
#include <cmath>
#include <functional>
#include <stack>
#include <type_traits>
#include <queue>
#include <memory>
#include <memory.h>
#include <time.h>
#include <ctime>
#pragma warning(disable:4996)
using namespace std;
#define Kirja_ES ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define pf push_front
#define irt insert
#define ll long long
#define int long long
#define ull unsigned long long
#define str string
#define vi vector<int>
#define vll vector<ll>
#define si set<int>
#define sll set<ll>
#define msi multiset<int>
#define msll multiset<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define left false
#define right true
int n, q, in1[300013] = {};
vector<vll> tree_v(1200013, vll(4)); //четное макс/мин нечетное макс/мин
vll build(int v, int left_tec, int right_tec)
{
	if (left_tec + 1 == right_tec)
	{
		tree_v[v][0] = 0;
		tree_v[v][1] = 0;
		tree_v[v][2] = in1[left_tec];
		tree_v[v][3] = in1[left_tec];
		return tree_v[v];
	}
	auto left_q = build(2 * v + 1, left_tec, (left_tec + right_tec) / 2);
	auto right_q = build(2 * v + 2, (left_tec + right_tec) / 2, right_tec);
	tree_v[v][0] = 0;
	tree_v[v][0] = 0;
	tree_v[v][2] = -1e16;
	tree_v[v][3] = 1e16;
	tree_v[v][0] = max(tree_v[v][0], max(left_q[0], right_q[0]));
	tree_v[v][0] = max(tree_v[v][0], left_q[0] + right_q[0]);
	tree_v[v][0] = max(tree_v[v][0], left_q[2] + right_q[2]);
	tree_v[v][0] = max(tree_v[v][0], left_q[2] - right_q[3]);

	tree_v[v][1] = min(tree_v[v][1], min(left_q[1], right_q[1]));
	tree_v[v][1] = min(tree_v[v][1], left_q[1] + right_q[1]);
	tree_v[v][1] = min(tree_v[v][1], left_q[3] - right_q[2]);
	//четное макс/мин нечетное макс/мин
	tree_v[v][2] = max(tree_v[v][2], max(left_q[2], right_q[2]));
	tree_v[v][2] = max(tree_v[v][2], left_q[0] + right_q[2]);
	tree_v[v][2] = max(tree_v[v][2], left_q[2] - right_q[1]);

	tree_v[v][3] = min(tree_v[v][3], min(left_q[3], right_q[3]));
	tree_v[v][3] = min(tree_v[v][3], left_q[1] + right_q[3]);
	tree_v[v][3] = min(tree_v[v][3], left_q[3] - right_q[0]);

	return tree_v[v];
}

vll update_t(int v, int left_tec, int right_tec, int index)
{
	if (left_tec + 1 == right_tec && left_tec == index)
	{
		tree_v[v][0] = 0;
		tree_v[v][1] = 0;
		tree_v[v][2] = in1[left_tec];
		tree_v[v][3] = in1[left_tec];
		return tree_v[v];
	}
	auto left_q = tree_v[2 * v + 1], right_q = tree_v[2 * v + 2];
	if (left_tec <= index && index < (left_tec + right_tec) / 2)
		left_q = update_t(2 * v + 1, left_tec, (left_tec + right_tec) / 2, index);
	if ((left_tec + right_tec) / 2 <= index && index < right_tec)
		right_q = update_t(2 * v + 2, (left_tec + right_tec) / 2, right_tec, index);
	tree_v[v][0] = 0;
	tree_v[v][0] = 0;
	tree_v[v][2] = -1e16;
	tree_v[v][3] = 1e16;

	//tree_v[v][0] = max(tree_v[v][0], max(left_q[0], right_q[0]));
	tree_v[v][0] = max(tree_v[v][0], left_q[0] + right_q[0]);
	tree_v[v][0] = max(tree_v[v][0], left_q[2] - right_q[3]);

	//tree_v[v][1] = min(tree_v[v][1], min(left_q[1], right_q[1]));
	tree_v[v][1] = min(tree_v[v][1], left_q[1] + right_q[1]);
	tree_v[v][1] = min(tree_v[v][1], left_q[3] - right_q[2]);

	//четное макс/мин нечетное макс/мин
	//tree_v[v][2] = max(tree_v[v][2], max(left_q[2], right_q[2]));
	tree_v[v][2] = max(tree_v[v][2], left_q[0] + right_q[2]);
	tree_v[v][2] = max(tree_v[v][2], left_q[2] - right_q[1]);

	//tree_v[v][3] = min(tree_v[v][3], min(left_q[3], right_q[3]));
	tree_v[v][3] = min(tree_v[v][3], left_q[1] + right_q[3]);
	tree_v[v][3] = min(tree_v[v][3], left_q[3] - right_q[0]);

	return tree_v[v];
}

signed main()
{
	Kirja_ES;
	//	freopen("input.in", "r", stdin);
	//	freopen("output.out", "w", stdout);
	int t;
	cin >> t;
	while (t--)
	{
		cin >> n >> q;
		for (int i = 0; i < n; ++i)
		{
			int h;
			cin >> h;
			in1[i] = h;
		}
		build(0, 0, n);
		cout << max(tree_v[0][2], tree_v[0][0]) << "\n";
		while (q--)
		{
			int l, r;
			cin >> l >> r;
			l--, r--;
			swap(in1[l], in1[r]);
			update_t(0, 0, n, l);
			update_t(0, 0, n, r);
			cout << tree_v[0][2] << "\n";
		}
	}
	return 0;
}