1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <algorithm>
5 #include <cstdlib>
6 #include <cmath>
7 #include <set>
8 #include <map>
9 #include <queue>
10 #include <vector>
11 using namespace std;
12
13 const int N = 10000 + 10;
14 double e[N], k[N], a[N], b[N], c[N];
15 vector <int> v[N];
16 bool find(int i, int fa)
17 {
18 if(v[i].size() == 1 && fa != -1)
19 {
20 a[i] = k[i];
21 b[i] = 1 - k[i] - e[i];
22 c[i] = 1 - k[i] - e[i];
23 return true;
24 }
25 a[i] = k[i];
26 b[i] = (1 - k[i] - e[i]) / v[i].size();
27 c[i] = 1 - k[i] - e[i];
28 double temp = 0;
29 for(int j = 0; j < (int)v[i].size(); j++)
30 {
31 if(v[i][j] == fa)
32 continue;
33 if(!find(v[i][j], i))
34 return false;
35 a[i] += b[i] * a[v[i][j]];
36 c[i] += b[i] * c[v[i][j]];
37 temp += b[i] * b[v[i][j]];
38 }
39 if(fabs(1 - temp) < 1e-10)
40 return false;
41 a[i] /= (1 - temp);
42 b[i] /= (1 - temp);
43 c[i] /= (1 - temp);
44 return true;
45 }
46 int main()
47 {
48 int t, n, x, y, cnt = 0;
49 scanf("%d", &t);
50 while(t--)
51 {
52 cnt++;
53 scanf("%d", &n);
54 for(int i = 1; i <= n; i++)
55 v[i].clear();
56 for(int i = 1; i < n; i++)
57 {
58 scanf("%d %d", &x, &y);
59 v[x].push_back(y);
60 v[y].push_back(x);
61 }
62 for(int i = 1; i <= n; i++){
63 scanf("%lf %lf", k + i, e + i);
64 k[i] /= 100.0;
65 e[i] /= 100.0;
66 }
67 cout << "Case " << cnt << ": "<<endl;
68 if(find(1, -1) && 1 - a[1] > 1e-10)
69 printf("%.6lf
", c[1]/(1 - a[1]));
70 else
71 cout << "impossible" << endl;
72 }
73 return 0;
74 }