#include <bits/stdc++.h>
using namespace std;
unsigned long long int bin_pow(unsigned long long int a,
                               unsigned long long int b) {
  unsigned long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a *= a;
    b = b >> 1;
  }
  return res;
}
void privet(unsigned long long int arr[], unsigned long long int n) {
  unsigned long long int res = 0;
  int f = 0;
  for (unsigned long long int i = 1; i < n; i++) {
    if (!f) {
      if (arr[i] < arr[i - 1]) {
        res += arr[i - 1];
        f = 1;
      }
    } else {
      if (arr[i] > arr[i - 1]) {
        res -= arr[i - 1];
        f = 0;
      }
    }
  }
  if (!f) res += arr[n - 1];
  cout << res << endl;
}
void solve() {
  unsigned long long int n, q;
  cin >> n >> q;
  unsigned long long int arr[n], l[q], r[q];
  for (unsigned long long int i = 0; i < n; i++) cin >> arr[i];
  for (unsigned long long int i = 0; i < q; i++) cin >> l[i] >> r[i];
  privet(arr, n);
  for (unsigned long long int i = 0; i < q; i++) {
    l[i]--;
    r[i]--;
    swap(arr[l[i]], arr[r[i]]);
    privet(arr, n);
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
