#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, i, ans = 0, z = 0;
    cin >> n;
    long long int a[n];
    for (i = 0; i < n; i++) cin >> a[i];
    if (n == 1) {
      cout << 0 << "\n";
      continue;
    }
    for (i = 1; i < n; i++) ans += max(z, (a[i - 1] - a[i]));
    cout << ans << "\n";
  }
}
