#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
struct Node {
  long long mx[2], mn[2];
} tree[1200005];
long long a[300005];
const long long inf = 1e18;
int T;
void pull(int i) {
  Node &l = tree[((i << 1) + 1)], &r = tree[((i << 1) + 2)];
  tree[i].mx[0] = max(l.mx[0] + r.mx[0], l.mx[1] - r.mn[1]);
  tree[i].mx[1] = max(l.mx[0] + r.mx[1], l.mx[1] - r.mn[0]);
  tree[i].mn[0] = min(l.mn[0] + r.mn[0], l.mn[1] - r.mx[1]);
  tree[i].mn[1] = min(l.mn[0] + r.mn[1], l.mn[1] - r.mx[0]);
}
void setv(int i, long long v) {
  tree[i].mx[0] = tree[i].mn[0] = 0;
  tree[i].mx[1] = tree[i].mn[1] = v;
}
void build(int i = 0, int l = 0, int r = T - 1) {
  if (l == r) {
    setv(i, a[l]);
    return;
  }
  int m = (l + r) >> 1;
  build(((i << 1) + 1), l, m);
  build(((i << 1) + 2), m + 1, r);
  pull(i);
}
int x;
void upd(int i = 0, int l = 0, int r = T - 1) {
  if (l == r) {
    setv(i, a[l]);
    return;
  }
  int m = (l + r) >> 1;
  if (x <= m)
    upd(((i << 1) + 1), l, m);
  else
    upd(((i << 1) + 2), m + 1, r);
  pull(i);
}
long long qry() { return max(tree[0].mx[0], tree[0].mx[1]); }
int main() {
  cin.tie(0), ios::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    int n, q;
    cin >> n >> q;
    T = n;
    for (int i = 0; i < n; i++) cin >> a[i];
    build();
    cout << qry() << "\n";
    while (q--) {
      int l, r;
      cin >> l >> r;
      --l;
      --r;
      swap(a[l], a[r]);
      x = l;
      upd();
      x = r;
      upd();
      cout << qry() << "\n";
    }
  }
  return 0;
}
