#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, i;
  cin >> n;
  vector<long long int> v(n);
  for (auto &i : v) cin >> i;
  ;
  long long int temp = v[n - 1], ans = 0;
  for (long long int i = n - 2; i >= 0; i -= 1) {
    if (v[i] <= v[i + 1])
      temp = v[i];
    else {
      ans += (v[i] - temp);
      temp = v[i];
    }
  }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
