#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T biton(T n, T pos) {
  return n((T)1 << pos);
}
template <class T>
inline T bitoff(T n, T pos) {
  return n & ~((T)1 << pos);
}
template <class T>
inline T ison(T n, T pos) {
  return (bool)(n & ((T)1 << pos));
}
template <class T>
inline T gcd(T a, T b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
inline int nxt() {
  int aaa;
  scanf("%d", &aaa);
  return aaa;
}
inline long long lxt() {
  long long aaa;
  scanf("%lld", &aaa);
  return aaa;
}
inline double dxt() {
  double aaa;
  scanf("%lf", &aaa);
  return aaa;
}
inline void vinput(int n, vector<int>& v) {
  for (int in, i = 0; i < n; i++) {
    cin >> in;
    v.push_back(in);
  }
}
inline void vout(vector<int> v) {
  for (auto it : v) cout << it << " ";
  cout << endl;
}
int cs = 0;
void solve() {
  int n;
  cin >> n;
  vector<int> v;
  vinput(n, v);
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    if (v[i] < v[i - 1]) ans += (v[i - 1] - v[i]);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.setf(ios::fixed);
  cout.precision(2);
  int tc = 1;
  cin >> tc;
  while (tc--) solve();
  return 0;
}
