#include <bits/stdc++.h>
using namespace std;
int T;
int N, Q;
int A[303030];
int NV = 1 << 20;
signed long long val[2 << 20][2][2];
void hoge(int a, int b, int c) {
  val[a][0][0] = -1LL << 60;
  val[a][0][1] = 1LL << 60;
  val[a][1][0] = -1LL << 60;
  val[a][1][1] = 1LL << 60;
  int i, j, k, l;
  for (i = 0; i < (2); i++)
    for (j = 0; j < (2); j++)
      for (k = 0; k < (2); k++)
        for (l = 0; l < (2); l++) {
          if (i == 0) {
            val[a][(i + k) % 2][0] =
                max(val[a][(i + k) % 2][0], val[b][i][j] + val[c][k][l]);
            val[a][(i + k) % 2][1] =
                min(val[a][(i + k) % 2][1], val[b][i][j] + val[c][k][l]);
          } else {
            val[a][(i + k) % 2][0] =
                max(val[a][(i + k) % 2][0], val[b][i][j] - val[c][k][l]);
            val[a][(i + k) % 2][1] =
                min(val[a][(i + k) % 2][1], val[b][i][j] - val[c][k][l]);
          }
        }
}
void update(int entry, int v) {
  entry += NV;
  val[entry][0][0] = val[entry][0][1] = 0;
  val[entry][1][0] = val[entry][1][1] = v;
  while (entry > 1) {
    entry >>= 1;
    hoge(entry, entry * 2, entry * 2 + 1);
  }
}
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &N, &Q);
    for (i = 0; i < (N); i++) {
      scanf("%d", &A[i]);
      update(i, A[i]);
    }
    (void)printf("%lld\n", max(val[1][0][0], val[1][1][0]));
    while (Q--) {
      int L, R;
      scanf("%d%d", &L, &R);
      L--, R--;
      swap(A[L], A[R]);
      update(L, A[L]);
      update(R, A[R]);
      (void)printf("%lld\n", max(val[1][0][0], val[1][1][0]));
    }
    for (i = 0; i < (N); i++) update(i, 0);
  }
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
