#include <bits/stdc++.h>
using namespace std;
using ll = long long;
long long ncr(int n, int r) {
  if (r > n - r) r = n - r;
  long long ans = 1;
  int i;
  for (i = 1; i <= r; i++) {
    ans *= n - r + i;
    ans /= i;
  }
  return ans;
}
ll mod(ll a, ll b, ll m) {
  if (b == 0) return 1;
  if (b % 2 == 0) {
    ll y = mod(a, b / 2, m);
    return (y * y) % m;
  } else {
    return ((a % m) * mod(a, b - 1, m)) % m;
  }
}
ll modinv(ll a, ll m) { return mod(a, m - 2, m); }
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> ops(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      ops[i] = 0;
    }
    for (int i = 1; i < n; i++) {
      if (a[i] < a[i - 1]) {
        ops[i] = a[i - 1] - a[i];
      }
    }
    ll sum = 0;
    for (auto x : ops) sum += x;
    cout << sum << endl;
  }
  return 0;
}
