#include <bits/stdc++.h>
using namespace std;
long long num[2000006];
long long inf = 1e18;
int main() {
  long long i, j, k, s, d, r, m, n, test, tc;
  cin >> test;
  for (tc = 1; tc <= test; tc++) {
    cin >> n;
    for (i = 1; i <= n; i++) cin >> num[i];
    long long mx = 0, mn = 0;
    s = 0;
    for (i = 1; i <= n; i++) {
      r = max(num[i - 1] - num[i], 0ll);
      s += r;
    }
    cout << s << endl;
  }
}
