#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, k, n, t, m, x, y, a, b, c, sum;
  vector<long long int> v;
  cin >> t;
  for (i = 1; i <= t; i++) {
    cin >> n;
    for (j = 0; j < n; j++) {
      cin >> a;
      v.push_back(a);
    }
    sum = 0;
    for (k = 0; k < n - 1; k++) {
      b = v[k] - v[k + 1];
      if (b > 0) sum = sum + b;
    }
    cout << sum << '\n';
    v.clear();
  }
}
