#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> a, pair<int, int> b) {
  return (a.first == b.first) ? a.second < b.second : a.first < b.first;
}
long long int modInverse(long long int a) {
  long long int m = 1000000007;
  long long int y = 0, x = 1;
  while (a > 1) {
    long long int q = a / m;
    long long int t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += 1000000007;
  return x;
}
long long int binpow(long long int a, long long int p) {
  if (p == 0) return 1;
  long long int ret = binpow(a, p / 2);
  ret *= ret;
  ret %= 1000000007;
  if (p % 2) {
    ret *= a;
    ret %= 1000000007;
  }
  return ret;
}
struct data {
  long long int pp, pn, np, nn;
};
data t[1200010];
data combine(data l, data r) {
  data res;
  res.pp = max(max(l.pp, r.pp), max(l.pn + r.pp, l.pp + r.np));
  res.pn = max(max(l.pn, r.pn), max(l.pp + r.nn, l.pn + r.pn));
  res.np = max(max(l.np, r.np), max(l.np + r.np, l.nn + r.pp));
  res.nn = max(max(l.nn, r.nn), max(l.np + r.nn, l.nn + r.pn));
  return res;
}
data make_data(long long int val) {
  data res;
  res.pp = val;
  res.pn = res.np = INT_MIN;
  res.nn = -val;
  return res;
}
void build(long long int a[], int v, int tl, int tr) {
  if (tl == tr) {
    t[v] = make_data(a[tl]);
  } else {
    int tm = (tl + tr) / 2;
    build(a, v * 2, tl, tm);
    build(a, v * 2 + 1, tm + 1, tr);
    t[v] = combine(t[v * 2], t[v * 2 + 1]);
  }
}
void update(int v, int tl, int tr, int pos, int new_val) {
  if (tl == tr) {
    t[v] = make_data(new_val);
  } else {
    int tm = (tl + tr) / 2;
    if (pos <= tm)
      update(v * 2, tl, tm, pos, new_val);
    else
      update(v * 2 + 1, tm + 1, tr, pos, new_val);
    t[v] = combine(t[v * 2], t[v * 2 + 1]);
  }
}
data query(int v, int tl, int tr, int l, int r) {
  if (l > r) return make_data(0);
  if (l == tl && r == tr) return t[v];
  int tm = (tl + tr) / 2;
  return combine(query(v * 2, tl, tm, l, min(r, tm)),
                 query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
void solve() {
  int n, q;
  cin >> n >> q;
  long long int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  build(arr, 1, 0, n - 1);
  cout << query(1, 0, n - 1, 0, n - 1).pp << '\n';
  int l, r;
  for (int i = 0; i < q; i++) {
    cin >> l >> r;
    l--;
    r--;
    int vl = arr[r];
    int vr = arr[l];
    arr[l] = vl;
    arr[r] = vr;
    update(1, 0, n - 1, l, vl);
    update(1, 0, n - 1, r, vr);
    cout << query(1, 0, n - 1, 0, n - 1).pp << '\n';
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1, nw = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
