#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 5000;
const ll INF = 1e18;
int T, n;
ll date[2][maxn], sum[2][maxn], sum_r[2][maxn], cost[2][maxn], cost_r[2][maxn];
ll dp[maxn][2];
void init() {
sum[0][1] = sum[1][1] = sum_r[0][n] = sum_r[1][n] = 0;
cost[0][1] = cost[1][1] = cost_r[0][n] = cost_r[1][n] = 0;
for (int k = 0; k <= 1; k++) {
for (int i = 2; i <= n; i++) {
sum[k][i] = sum[k][i-1] + date[k][i-1];
cost[k][i] = cost[k][i-1] + sum[k][i];
}
for (int i = n-1; i >= 1; i--) {
sum_r[k][i] = sum_r[k][i+1] + date[k][i+1];
cost_r[k][i] = cost_r[k][i+1] + sum_r[k][i];
}
}
}
ll C(int k, int from, int to) {
if (from == to) return 0;
if (from < to) return cost[k][to] - cost[k][from] - sum[k][from] * (to - from);
else return cost_r[k][to] - cost_r[k][from] - sum_r[k][from] * (from - to);
}
void solve() {
for (int i = 1; i < n; i++) {
for (int k = 0; k <= 1; k++) {
dp[i][k] = C(k, 1, i+1);
}
}
dp[n][0] = dp[n][1] = INF;
for (int i = 2; i < n; i++) {
for (int k = 0; k <= 1; k++) {
for (int j = 1; j <= i-1; j++) {
int mid = (j + i+1)>>1;
dp[i][k] = min(dp[i][k], dp[j][k^1] + C(k, mid, j) + C(k, mid+1, i+1));
}
}
}
for (int k = 0; k <= 1; k++) {
for (int j = 1; j <= n-1; j++) {
dp[n][k] = min(dp[n][k], dp[j][k^1] + C(k, n, j));
}
}
}
int main() {
scanf("%d", &T);
for (int kase = 1; kase <= T; kase++) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld %lld", &date[0][i], &date[1][i]);
}
init();
solve();
printf("Case #%d: %lld\n", kase, min(dp[n][0], dp[n][1]));
}
return 0;
}