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