#include <bits/stdc++.h>
using namespace std;
const long long int nax = 1e5 + 5;
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (auto &x : a) cin >> x;
  long long int sum = 0, mx = 0;
  for (long long int i = 0; i < n - 1; i++) {
    sum += max((long long int)0, a[i] - a[i + 1]);
  }
  cout << sum << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
