#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    ll ans = 0;
    for (int i = 1; i < n; i++) {
      if (a[i] < a[i - 1]) {
        ans += (a[i - 1] - a[i]);
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
