#include <bits/stdc++.h>
using namespace std;
const int64_t I64 = int64_t(2e18) + 5;
const long long MOD = 1e9 + 7;
const long long inf = 1e18 + 7;
int t;
void sol() {
  int n;
  cin >> n;
  long long a[n];
  for (auto &i : a) cin >> i;
  int l = 0;
  vector<long long> res;
  long long r = 0;
  for (int i = 1; i < n; ++i) {
    if (a[i] < a[i - 1]) {
      r += a[i - 1] - a[i];
      continue;
    } else {
      res.push_back(r);
      r = 0;
    }
  }
  res.push_back(r);
  r = 0;
  for (auto i : res) {
    r += i;
  }
  cout << r << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  if (1) {
    cin >> t;
    while (t--) sol();
  } else
    sol();
}
