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