#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
  return x * f;
}
int T, n, m, a[200010];
int main() {
  T = read();
  while (T--) {
    n = read();
    long long ans = 0;
    for (int i = 1; i <= n; i++) a[i] = read();
    a[0] = a[1];
    for (int i = n; i >= 1; i--) {
      int t = i;
      while (t > 1 && a[t - 1] <= a[t]) t--;
      ans += a[t - 1] - a[t];
      i = t;
    }
    cout << ans << endl;
  }
}
