#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  char ch = getchar();
  long long s = 0, w = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * w;
}
long long T;
long long n, q, a[300010];
struct matrix {
  long long a[3][3];
  matrix() {
    for (register long long i = 0; i <= 2; i++)
      for (register long long j = 0; j <= 2; j++) a[i][j] = -1e18;
  }
} t[300010 << 2];
matrix operator*(matrix a, matrix b) {
  matrix c;
  for (register long long i = 1; i <= 2; i++)
    for (register long long j = 1; j <= 2; j++)
      for (register long long k = 1; k <= 2; k++)
        c.a[i][j] = max(c.a[i][j], a.a[i][k] + b.a[k][j]);
  return c;
}
inline void pushup(long long x) { t[x] = t[(x << 1)] * t[(x << 1 | 1)]; }
void build(long long l, long long r, long long x) {
  if (l == r) {
    t[x].a[1][1] = 0, t[x].a[1][2] = a[l], t[x].a[2][1] = -a[l],
    t[x].a[2][2] = 0;
    return;
  }
  build(l, ((l + r) >> 1), (x << 1));
  build(((l + r) >> 1) + 1, r, (x << 1 | 1));
  pushup(x);
}
void upd(long long l, long long r, long long x, long long pos) {
  if (l == r) {
    t[x].a[1][1] = 0, t[x].a[1][2] = a[l], t[x].a[2][1] = -a[l],
    t[x].a[2][2] = 0;
    return;
  }
  if (pos <= ((l + r) >> 1))
    upd(l, ((l + r) >> 1), (x << 1), pos);
  else
    upd(((l + r) >> 1) + 1, r, (x << 1 | 1), pos);
  pushup(x);
}
inline void Solve() {
  matrix ans;
  ans.a[1][1] = 0, ans.a[1][2] = 0;
  ans = ans * t[1];
  printf("%lld\n", max(ans.a[1][1], ans.a[1][2]));
}
int main() {
  T = read();
  while (T--) {
    n = read(), q = read();
    for (register long long i = 1; i <= n; i++) a[i] = read();
    build(1, n, 1);
    Solve();
    while (q--) {
      long long x = read(), y = read();
      swap(a[x], a[y]);
      upd(1, n, 1, x);
      upd(1, n, 1, y);
      Solve();
    }
  }
  return 0;
}
