#include #include #include using namespace std; void getint(int &x) { int ch = x = 0; while (!isdigit(ch = getchar())) ; for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; } const int N = 105; int a[N], p[N], dp[N]; int main() { int T, c; getint(T); while (T--) { getint(c); for (int i = 1; i <= c; i++) getint(a[i]), getint(p[i]), a[i] += a[i - 1]; for (int i = 1; i <= c; i++) { dp[i] = (a[i] - a[i - 1] + 10) * p[i] + dp[i - 1]; for (int j = 0; j < i; j++) dp[i] = min(dp[i], dp[j] + (a[i] - a[j] + 10) * p[i]); } printf("%d\n", dp[c]); } return 0; }