/***********Template Starts Here***********/
#include <bits/stdc++.h>
#define pb push_back
#define nl puts ("")
#define sp printf ( " " )
#define phl printf ( "hello\n" )
#define ff first
#define ss second
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define MP make_pair
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define SQ(x) ((x)*(x))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define ALL(x) (x).begin(),(x).end()
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
using namespace std;
typedef long long vlong;
typedef unsigned long long uvlong;
typedef pair < int, int > pii;
typedef pair < vlong, vlong > pll;
typedef vector<pii> vii;
typedef vector<int> vi;
inline vlong gcd ( vlong a, vlong b ) {
a = ABS ( a ); b = ABS ( b );
while ( b ) { a = a % b; swap ( a, b ); } return a;
}
/***********Template Ends Here***********/
///Custom Fraction Class
class Fraction {
vlong numerator, denominator;
void simplify() {
vlong g = gcd ( numerator, denominator );
numerator /= g;
denominator /= g;
if ( denominator < 0 ) {
numerator *= -1;
denominator *= -1;
}
}
public:
Fraction () {
numerator = 0;
denominator = 1;
}
Fraction ( vlong a, vlong b ) {
numerator = a;
denominator = b;
simplify();
}
Fraction ( vlong x ) {
numerator = x;
denominator = 1;
}
void operator = ( Fraction b ) {
numerator = b.numerator;
denominator = b.denominator;
}
Fraction operator + ( Fraction b ) { ///Addition
Fraction res;
res.denominator = ABS( LCM(denominator,b.denominator) );
res.numerator = (res.denominator/denominator)*numerator + (res.denominator/b.denominator)*b.numerator;
res.simplify();
return res;
}
void print() {
printf ( "%lld/%lld",numerator, denominator );
}
};
///Calculate combinations
vlong nck[25][25];
void calcNCK(int n) {
nck[0][0] = 1;
FOR(i,1,n) {
FOR(j,0,n) {
if ( j == 0 ) nck[i][j] = 1;
else nck[i][j] = nck[i-1][j-1] + nck[i-1][j];
}
}
}
void precal() {
calcNCK(20);
}
int menu[10010], item[10010];
///DP to find expected value
Fraction dp ( int pos ) {
if ( pos < 0 ) return Fraction(0ll);
Fraction res;
vlong total = nck[ menu[pos] ][ item[pos] ];
vlong chicken = nck[ menu[pos]-1 ][ item[pos]-1 ];
Fraction p ( chicken, total ), q ( total - chicken, total ); ///Calculate probabilities.
res = p + dp ( pos - 1 );
return res;
}
int main () {
precal();
#ifdef forthright48
freopen ( "input.txt", "r", stdin );
//freopen ( "output.txt", "w", stdout );
#endif // forthright48
int kase, cnt = 0;
scanf ( "%d", &kase );
while ( kase-- ) {
int m;
scanf ( "%d", &m );
FOR(i,0,m-1) {
scanf ( "%d %d", &menu[i], &item[i] );
}
Fraction res = dp ( m - 1 );
printf ( "Case %d: ", ++cnt ); res.print(); nl;
}
return 0;
}
LyoqKioqKioqKioqVGVtcGxhdGUgU3RhcnRzIEhlcmUqKioqKioqKioqKi8KI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIG5sIHB1dHMgKCIiKQojZGVmaW5lIHNwIHByaW50ZiAoICIgIiApCiNkZWZpbmUgcGhsIHByaW50ZiAoICJoZWxsb1xuIiApCiNkZWZpbmUgZmYgZmlyc3QKI2RlZmluZSBzcyBzZWNvbmQKI2RlZmluZSBQT1BDT1VOVCBfX2J1aWx0aW5fcG9wY291bnRsbAojZGVmaW5lIFJJR0hUTU9TVCBfX2J1aWx0aW5fY3R6bGwKI2RlZmluZSBMRUZUTU9TVCh4KSAoNjMtX19idWlsdGluX2NsemxsKCh4KSkpCiNkZWZpbmUgTVAgbWFrZV9wYWlyC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gYSAlIGI7IHN3YXAgKCBhLCBiICk7IH0gcmV0dXJuIGE7Cn0KCi8qKioqKioqKioqKlRlbXBsYXRlIEVuZHMgSGVyZSoqKioqKioqKioqLwovLy9DdXN0b20gRnJhY3Rpb24gQ2xhc3MKY2xhc3MgRnJhY3Rpb24gewogICAgdmxvbmcgbnVtZXJhdG9yLCBkZW5vbWluYXRvcjsKCiAgICB2b2lkIHNpbXBsaWZ5KCkgewogICAgICAgIHZsb25nIGcgPSBnY2QgKCBudW1lcmF0b3IsIGRlbm9taW5hdG9yICk7CiAgICAgICAgbnVtZXJhdG9yIC89IGc7CiAgICAgICAgZGVub21pbmF0b3IgLz0gZzsKICAgICAgICBpZiAoIGRlbm9taW5hdG9yIDwgMCApIHsKICAgICAgICAgICAgbnVtZXJhdG9yICo9IC0xOwogICAgICAgICAgICBkZW5vbWluYXRvciAqPSAtMTsKICAgICAgICB9CiAgICB9CgpwdWJsaWM6CiAgICBGcmFjdGlvbiAoKSB7CiAgICAgICAgbnVtZXJhdG9yID0gMDsKICAgICAgICBkZW5vbWluYXRvciA9IDE7CiAgICB9CiAgICBGcmFjdGlvbiAoIHZsb25nIGEsIHZsb25nIGIgKSB7CiAgICAgICAgbnVtZXJhdG9yID0gYTsKICAgICAgICBkZW5vbWluYXRvciA9IGI7CiAgICAgICAgc2ltcGxpZnkoKTsKICAgIH0KICAgIEZyYWN0aW9uICggdmxvbmcgeCApIHsKICAgICAgICBudW1lcmF0b3IgPSB4OwogICAgICAgIGRlbm9taW5hdG9yID0gMTsKICAgIH0KICAgIHZvaWQgb3BlcmF0b3IgPSAoIEZyYWN0aW9uIGIgKSB7CiAgICAgICAgbnVtZXJhdG9yID0gYi5udW1lcmF0b3I7CiAgICAgICAgZGVub21pbmF0b3IgPSBiLmRlbm9taW5hdG9yOwogICAgfQoKICAgIEZyYWN0aW9uIG9wZXJhdG9yICsgKCBGcmFjdGlvbiBiICkgeyAvLy9BZGRpdGlvbgogICAgICAgIEZyYWN0aW9uIH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