#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5, mod = 998244353;
template <class o>
inline void qr(o &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + (c ^ 48);
    c = getchar();
  }
  x *= f;
}
template <class o>
void qw(o x) {
  if (x / 10) qw(x / 10);
  putchar(x % 10 + 48);
}
template <class o>
void pr1(o x) {
  if (x < 0) putchar('-'), x = -x;
  qw(x);
  putchar(' ');
}
template <class o>
void pr2(o x) {
  if (x < 0) putchar('-'), x = -x;
  qw(x);
  puts("");
}
inline int ksm(int a, int b = mod - 2) {
  int ans = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) ans = 1ll * ans * a % mod;
  return ans;
}
int a[N];
struct Seg {
  long long mx[2], mn[2], sum;
  Seg() { mx[0] = mx[1] = mn[0] = mn[1] = sum = 0ll; }
  Seg operator+(const Seg &a) const {
    Seg b = *this;
    b.sum = max(b.sum, a.sum);
    for (int i = 0; i < 2; ++i) {
      b.mn[i] = min(b.mn[i], a.mn[i]);
      b.mx[i] = max(b.mx[i], a.mx[i]);
    }
    for (int i = 0; i < 2; ++i)
      for (int j = 0; j < 2; ++j) {
        b.mn[(i + j) & 1] =
            min(b.mn[(i + j) & 1], mn[i] + (i & 1 ? -a.mx[j] : a.mn[j]));
        b.mx[(i + j) & 1] =
            max(b.mx[(i + j) & 1], mx[i] + (i & 1 ? -a.mn[j] : a.mx[j]));
      }
    for (int i = 0; i < 2; ++i) b.sum = max(b.sum, b.mx[i]);
    return b;
  }
} t[N << 2];
void build(int p, int l, int r) {
  if (l == r) {
    t[p].mx[0] = t[p].mn[0] = 0;
    t[p].mx[1] = t[p].mn[1] = a[l];
    t[p].sum = a[l];
    return;
  }
  int mid = l + r >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  t[p] = t[p << 1] + t[p << 1 | 1];
}
void change(int p, int l, int r, int pos, int d) {
  if (l == r) {
    t[p].mx[0] = t[p].mn[0] = 0;
    t[p].mx[1] = t[p].mn[1] = d;
    t[p].sum = d;
    return;
  }
  int mid = l + r >> 1;
  if (pos <= mid)
    change(p << 1, l, mid, pos, d);
  else
    change(p << 1 | 1, mid + 1, r, pos, d);
  t[p] = t[p << 1] + t[p << 1 | 1];
}
int main() {
  int T;
  qr(T);
  while (T--) {
    int n, m;
    qr(n);
    qr(m);
    for (int i = 1; i <= n; ++i) qr(a[i]);
    build(1, 1, n);
    pr2(t[1].sum);
    for (int i = 1; i <= m; ++i) {
      int l, r;
      qr(l), qr(r);
      change(1, 1, n, l, a[r]);
      change(1, 1, n, r, a[l]);
      swap(a[l], a[r]);
      pr2(t[1].sum);
    }
  }
  return 0;
}
