#include <bits/stdc++.h>
using namespace std;
void reader() {}
void fastIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long b[n];
  for (long long i = 0; i < n; i++) b[i] = a[i];
  long long sum = 0;
  for (long long i = 0; i < n - 1; i++) {
    if (a[i] > a[i + 1]) {
      sum += abs(a[i + 1] - a[i]);
      a[i + 1] = a[i];
    }
  }
  cout << sum;
  cout << "\n";
}
signed main() {
  reader();
  fastIO();
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
