#include <bits/stdc++.h>
using namespace std;
int q, n;
long long arr[3 * 100001], brr[3 * 100001];
long long dp[3 * 100001][10];
int main() {
  for (int i = 0; i < 3 * 100001; ++i)
    for (int j = 0; j < 10; ++j) dp[i][j] = LLONG_MAX;
  cin >> q;
  n = 0;
  while (q--) {
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < 10; ++j) dp[i][j] = LLONG_MAX;
    cin >> n;
    for (int i = 0; i < n; ++i) {
      cin >> arr[i] >> brr[i];
    }
    for (int i = 0; i < 10; ++i) dp[0][i] = brr[0] * i;
    for (int i = 1; i < n; ++i) {
      for (int j = 0; j < 10; ++j) {
        for (int k = 0; k < 10; ++k) {
          if (arr[i] + j != arr[i - 1] + k) {
            dp[i][j] = min(dp[i][j], dp[i - 1][k] + brr[i] * j);
          }
        }
      }
    }
    long long ans = dp[n - 1][0];
    for (int i = 0; i < 10; ++i) ans = min(ans, dp[n - 1][i]);
    cout << ans << endl;
  }
  return 0;
}
