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