#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
vector<long long> adj[N];
long long tin[N], tout[N];
long long timer;
void euler_tour1(long long x, long long par) {
  tin[x] = timer++;
  for (auto i : adj[x]) {
    if (i != par) {
      euler_tour1(i, x);
      cout << x << " ";
      tout[x] = timer++;
    }
  }
}
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long ans = 0;
    vector<long long> a(n);
    for (long long i = 0; i < n; i++) cin >> a[i];
    for (long long i = n - 1; i >= 1; i--)
      if (a[i - 1] > a[i]) ans += a[i - 1] - a[i];
    cout << ans << endl;
    ;
  }
  return 0;
}
