#include <bits/stdc++.h>
using namespace std;
struct node {
  int64_t pp;
  int64_t nn;
  int64_t pn;
  int64_t np;
};
const int64_t MAXN = 3e5 + 5;
int64_t n, q;
int64_t a[MAXN];
node tree[4 * MAXN];
void merge(node &cur, node l, node r) {
  cur.pp = max(l.pp + r.np, l.pn + r.pp);
  cur.nn = max(l.nn + r.pn, l.np + r.nn);
  cur.np = max(l.nn + r.pp, l.np + r.np);
  cur.pn = max(l.pn + r.pn, l.pp + r.nn);
}
void build(int64_t v, int64_t tl, int64_t tr) {
  if (tl == tr) {
    tree[v] = {a[tl], -a[tl], 0, 0};
  } else {
    int64_t tmid = (tl + tr) / 2;
    build(2 * v, tl, tmid);
    build(2 * v + 1, tmid + 1, tr);
    merge(tree[v], tree[2 * v], tree[2 * v + 1]);
  }
}
node query(int64_t v, int64_t tl, int64_t tr, int64_t l, int64_t r) {
  if (tl > r || l > tr) return {0, 0, 0, 0};
  if (tl >= l && tr <= r) return tree[v];
  int64_t tmid = (tl + tr) / 2;
  node cur;
  merge(cur, query(2 * v, tl, tmid, l, r),
        query(2 * v + 1, tmid + 1, tr, l, r));
  return cur;
}
void update(int64_t v, int64_t tl, int64_t tr, int64_t idx, int64_t val) {
  if (tl == tr)
    tree[v] = {val, -val, 0, 0};
  else {
    int64_t tmid = (tl + tr) / 2;
    if (idx > tmid)
      update(2 * v + 1, tmid + 1, tr, idx, val);
    else
      update(2 * v, tl, tmid, idx, val);
    merge(tree[v], tree[2 * v], tree[2 * v + 1]);
  }
}
int64_t query() {
  node cur = query(1, 0, n - 1, 0, n - 1);
  return max(cur.pp, cur.pn);
}
void update(int64_t i, int64_t j) {
  update(1, 0, n - 1, i, a[j]);
  update(1, 0, n - 1, j, a[i]);
  swap(a[i], a[j]);
}
int32_t main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int64_t t;
  cin >> t;
  while (t--) {
    cin >> n >> q;
    for (int64_t i = 0; i < n; ++i) cin >> a[i];
    build(1, 0, n - 1);
    cout << query() << "\n";
    while (q--) {
      int64_t l, r;
      cin >> l >> r;
      --l;
      --r;
      update(l, r);
      cout << query() << "\n";
    }
  }
  return 0;
}
