#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<vector<long long>> dp(n, vector<long long>(10, 0));
    vector<long long> arr(n);
    vector<long long> cost(n);
    for (long long i = 0; i < (n); i++) {
      cin >> arr[i] >> cost[i];
    }
    for (long long i = 0; i < 10; i++) {
      dp[0][i] = cost[0] * i;
    }
    for (long long i = 1; i < n; i++) {
      for (long long j = 0; j < 10; j++) {
        dp[i][j] = inf;
        for (long long k = 0; k < 10; k++) {
          if (arr[i - 1] + k == arr[i] + j) continue;
          dp[i][j] = min(dp[i][j], dp[i - 1][k] + j * cost[i]);
        }
      }
    }
    long long ans = inf;
    for (long long i = 0; i < 10; i++) {
      ans = min(ans, dp[n - 1][i]);
    }
    cout << ans << endl;
  }
}
