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