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