#include <bits/stdc++.h>
int n;
using namespace std;
long long ans(long long n, long long a[]) {
  long long b[n];
  b[0] = 1;
  vector<long long> x;
  for (long long i = 1; i < n; i++) {
    if (a[i] < a[i + 1]) {
      b[i] = 1;
    } else {
      b[i] = 0;
    }
  }
  for (long long i = 1; i < n; i++) {
    if (b[i] == 0 && b[i - 1] == 1) {
      x.push_back(a[i]);
    }
    if (b[i] == 1 && b[i - 1] == 0) {
      x.push_back(a[i]);
    }
  }
  long long s = x.size();
  if (s % 2 == 0) x.push_back(a[n]);
  long long sum = 0;
  long long f = s / 2;
  for (long long i = 0; i < 2 * f + 1; i++) {
    if (i % 2 == 0) {
      sum = sum + x[i];
    } else {
      sum = sum - x[i];
    }
  }
  return sum;
}
int32_t main() {
  long long t;
  cin >> t;
  for (long long h = 0; h < t; h++) {
    long long n, q;
    cin >> n >> q;
    long long a[n + 1];
    long long A[n + 1];
    a[0] = 0;
    for (long long i = 1; i <= n; i++) {
      cin >> a[i];
      A[i] = a[i];
    }
    cout << ans(n, a) << endl;
    for (long long i = 0; i < q; i++) {
      long long l, r;
      cin >> l >> r;
      A[l] = a[r];
      A[r] = a[l];
      cout << ans(n, A) << endl;
      A[l] = a[l];
      A[r] = a[r];
    }
  }
}
