#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int inf = 2e18 + 5;
double PI = 3.14159265358979323846;
struct node {
  long long int minodd, maxodd, mineven, maxeven;
  node()
      : minodd(LLONG_MAX),
        maxodd(LLONG_MIN),
        mineven(LLONG_MAX),
        maxeven(LLONG_MIN) {}
  node(int x) : minodd(x), maxodd(x), mineven(0), maxeven(0) {}
};
template <typename T>
class segmentTree {
 public:
  int n;
  vector<T> t;
  vector<int> lazy;
  T out = node();
  template <typename U>
  void init(const U &arr, int N) {
    n = N;
    t.assign(4 * N + 7, 0);
    lazy.assign(4 * N + 7, 0);
    build(arr, 1, 0, n - 1);
  }
  template <typename U>
  void apply(int i, U val) {
    t[i] = node(val);
  }
  template <typename U>
  void pointApply(int i, U val) {
    t[i] = node(val);
  }
  void unite(T &cur, T &left, T &right) {
    cur.minodd = min({left.minodd, right.minodd, left.minodd - right.maxeven,
                      left.mineven + right.minodd});
    cur.mineven =
        min({left.mineven, right.mineven, left.mineven + right.mineven,
             left.minodd - right.maxodd});
    cur.maxodd = max({left.maxodd, right.maxodd, left.maxeven + right.maxodd,
                      left.maxodd - right.mineven});
    cur.maxeven =
        max({left.maxeven, right.maxeven, left.maxeven + right.maxeven,
             left.maxodd - right.minodd});
  }
  void propagate(int i, int s, int e) {}
  template <typename U>
  void build(const U &arr, int i, int s, int e) {
    if (s == e) {
      apply(i, arr[s]);
      return;
    }
    int mid = (s + e) >> 1;
    build(arr, 2 * i, s, mid);
    build(arr, 2 * i + 1, mid + 1, e);
    unite(t[i], t[i * 2], t[i * 2 + 1]);
  }
  template <typename U>
  void pointUpdateHelper(int idx, U val, int i, int s, int e) {
    if (idx > e || idx < s) {
      return;
    }
    if (s == e) {
      pointApply(i, val);
      return;
    }
    int mid = (s + e) >> 1;
    pointUpdateHelper(idx, val, 2 * i, s, mid);
    pointUpdateHelper(idx, val, 2 * i + 1, mid + 1, e);
    unite(t[i], t[i * 2], t[i * 2 + 1]);
  }
  template <typename U>
  void rangeUpdateHelper(int ri, int rj, U val, int i, int s, int e) {
    if (lazy[i]) {
      propagate(i, s, e);
    }
    if (ri > e || rj < s) {
      return;
    }
    if (s >= ri && e <= rj) {
      lazy[i] = val;
      propagate(i, s, e);
      return;
    }
    int mid = (s + e) >> 1;
    rangeUpdateHelper(ri, rj, val, 2 * i, s, mid);
    rangeUpdateHelper(ri, rj, val, 2 * i + 1, mid + 1, e);
    unite(t[i], t[i * 2], t[i * 2 + 1]);
  }
  T queryHelper(int qi, int qj, int i, int s, int e) {
    if (lazy[i]) {
      propagate(i, s, e);
    }
    if (qi > e || qj < s) {
      return out;
    }
    if (s >= qi && e <= qj) {
      return t[i];
    }
    int mid = (s + e) >> 1;
    T left = queryHelper(qi, qj, 2 * i, s, mid);
    T right = queryHelper(qi, qj, 2 * i + 1, mid + 1, e);
    T cur;
    unite(cur, left, right);
    return cur;
  }
  template <typename U>
  void pointUpdate(int idx, U val) {
    pointUpdateHelper(idx, val, 1, 0, n - 1);
  }
  template <typename U>
  void rangeUpdate(int ri, int rj, U val) {
    rangeUpdateHelper(ri, rj, val, 1, 0, n - 1);
  }
  T query(int qi, int qj) { return queryHelper(qi, qj, 1, 0, n - 1); }
};
int n;
void solve() {
  cin >> n;
  int m;
  cin >> m;
  vector<long long int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  segmentTree<node> s;
  s.init(a, n);
  cout << s.query(0, n).maxodd << "\n";
  while (m--) {
    int l, r;
    cin >> l >> r;
    --l;
    --r;
    swap(a[l], a[r]);
    s.pointUpdate(l, a[l]);
    s.pointUpdate(r, a[r]);
    cout << s.query(0, n).maxodd << "\n";
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) solve();
  return 0;
}
