#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long n, a[N];
void solve() {
  cin >> n;
  long long ans = 0;
  for (long long i = 1; i <= n; ++i) cin >> a[i];
  for (long long i = 1; i < n; ++i) {
    if (a[i + 1] < a[i]) {
      ans += -a[i + 1] + a[i];
    }
  }
  cout << ans << "\n";
  return;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
}
