#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
inline long long int GCD(long long int x, long long int y) {
  if (x < y) swap(x, y);
  if (x == 0) return y;
  if (y == 0) return x;
  return GCD(x % y, y);
}
long long int phi(long long int n) {
  long long int result = n;
  for (long long int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      while (n % i == 0) n /= i;
      result -= result / i;
    }
  }
  if (n > 1) result -= result / n;
  return result;
}
long long int power(long long int x, long long int n, long long int mod) {
  long long int res = 1;
  x %= mod;
  while (n) {
    if (n & 1) {
      res = ((res * x) % mod + mod) % mod;
    }
    x = ((x * x) % mod + mod) % mod;
    n >>= 1;
  }
  return res;
}
const int MAXN = 3e5 + 5;
long long int N;
long long int tree[4 * MAXN][4], A[MAXN];
inline void merge(long long int ans[4], long long int left[4],
                  long long int right[4]) {
  ans[0] = max(left[0], right[0]);
  ans[0] = max(ans[0], left[1] - right[3]);
  ans[0] = max(ans[0], left[0] + right[0]);
  ans[1] = max(left[1], right[1]);
  ans[1] = max(ans[1], left[1] - right[2]);
  ans[1] = max(ans[1], left[0] + right[1]);
  ans[3] = min(left[3], right[3]);
  ans[3] = min(ans[3], left[3] - right[0]);
  ans[3] = min(ans[3], left[2] + right[3]);
  ans[2] = min(left[2], right[2]);
  ans[2] = min(ans[2], left[3] - right[1]);
  ans[2] = min(ans[2], left[2] + right[2]);
}
void build(long long int node, long long int start, long long int end) {
  if (start == end) {
    tree[node][0] = 0;
    tree[node][1] = A[start];
    tree[node][2] = 0;
    tree[node][3] = A[start];
  } else {
    long long int mid = (start + end) / 2;
    build(2 * node, start, mid);
    build(2 * node + 1, mid + 1, end);
    merge(tree[node], tree[2 * node], tree[2 * node + 1]);
  }
}
void update(long long int node, long long int start, long long int end,
            long long int l, long long int r, long long int val) {
  if (start > end || l > end || r < start) return;
  if (l <= start && end <= r) {
    tree[node][0] = 0;
    tree[node][1] = val;
    tree[node][2] = 0;
    tree[node][3] = val;
    return;
  }
  long long int mid = (start + end) / 2;
  if (l <= mid) update(2 * node, start, mid, l, r, val);
  if (mid + 1 <= r) update(2 * node + 1, mid + 1, end, l, r, val);
  merge(tree[node], tree[2 * node], tree[2 * node + 1]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int Q;
  long long int test;
  cin >> test;
  while (test--) {
    cin >> N >> Q;
    for (long long int i = 1; i <= N; i++) {
      cin >> A[i];
    }
    build(1, 1, N);
    long long int ans = max(tree[1][0], tree[1][1]);
    cout << ans << endl;
    long long int l, r;
    while (Q--) {
      cin >> l >> r;
      swap(A[l], A[r]);
      update(1, 1, N, l, l, A[l]);
      update(1, 1, N, r, r, A[r]);
      long long int ans = max(tree[1][0], tree[1][1]);
      cout << ans << endl;
    }
  }
}
