#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long T;
  cin >> T;
  while (T--) {
    long long n, i;
    cin >> n;
    long long a[n];
    for (i = 0; i < n; i++) cin >> a[i];
    long long x = a[0];
    long long s = 0;
    for (i = 0; i < n - 1; i++) {
      s = s + (long long)max((a[i] - a[i + 1]), (long long)0);
    }
    cout << s, cout << "\n";
  }
}
