#include <bits/stdc++.h>
using namespace std;
void beat() {
  int64_t n;
  cin >> n;
  vector<int64_t> a(n);
  for (int64_t& i : a) cin >> i;
  int64_t m = a[0], count = 0;
  for (int64_t i = 1; i < n; ++i) {
    if (a[i] < m) {
      count += m - a[i];
      m = a[i];
    } else {
      m = a[i];
    }
  }
  cout << count << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int64_t t;
  cin >> t;
  while (t--) beat();
  return 0;
}
