#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int pow(double, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main(void) {
  int t, m;
  double c, d, p;
  scanf("%d", &t);
  while (t-- != 0) {
    scanf("%d", &m);
    scanf("%lf", &p);
    if (p == 1) {
      if (m % 2 == 0) {
        printf("0.0 1000000000.0\n");
      } else
        printf("1000000000.0 0.0\n");
      continue;
    }
    if (m == 1) {
      printf("1000000000.0 0.0\n");
    } else {
      d = (1000000000 * p) * (1 - pow((-p), m - 1)) / (1 + p);
      c = 1000000000 - d;
      printf("%lf %lf\n", c, d);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1291 <main+0x161>
lea    0xea4(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xe95(%rip),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movsd  -0x28(%rbp),%xmm0
movsd  0xe6a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11e0 <main+0xb0>
jp     11e0 <main+0xb0>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11cd <main+0x9d>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11db <main+0xab>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1151 <main+0x21>
cmpl   $0x1,-0xc(%rbp)
jne    11fd <main+0xcd>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    128c <main+0x15c>
movsd  0xe03(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
call   1050 <pow@plt>
movsd  -0x30(%rbp),%xmm0
mov    %eax,%ecx
mov    $0x1,%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdac(%rip),%xmm1
addsd  -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xd9e(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    0xdb6(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
jmp    1151 <main+0x21>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xecb(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
subl   $0x1,(%rsp)
jae    1176 <main+0x36>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xea3(%rip),%r14
lea    0x4(%rsp),%r15
lea    0xe9a(%rip),%r12
lea    0x8(%rsp),%rbx
lea    0xeac(%rip),%r13
lea    0xe94(%rip),%rbp
jmp    11ae <main+0x6e>
xchg   %ax,%ax
mov    %rbp,%rdi
call   1030 <puts@plt>
subl   $0x1,(%rsp)
jb     1165 <main+0x25>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movsd  0x8(%rsp),%xmm0
ucomisd 0xe2a(%rip),%xmm0
mov    0x4(%rsp),%edi
jne    11f0 <main+0xb0>
jp     11f0 <main+0xb0>
test   $0x1,%dil
jne    11a0 <main+0x60>
mov    %r13,%rdi
jmp    11a3 <main+0x63>
nopl   0x0(%rax)
cmp    $0x1,%edi
je     11a0 <main+0x60>
movapd %xmm0,%xmm2
movsd  0xe07(%rip),%xmm1
mulsd  %xmm1,%xmm2
movapd %xmm2,0x10(%rsp)
xorpd  0xdfd(%rip),%xmm0
add    $0xffffffff,%edi
call   1060 <pow@plt>
mov    $0x1,%ecx
sub    %eax,%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
mulsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
addsd  0xdc3(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xdbf(%rip),%xmm0
subsd  %xmm1,%xmm0
lea    0xdd3(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
subl   $0x1,(%rsp)
jae    11ae <main+0x6e>
jmp    1165 <main+0x25>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [18 x i8] c"0.0 1000000000.0\0A\00"
@.str.3 = [18 x i8] c"1000000000.0 0.0\0A\00"
@.str.4 = [9 x i8] c"%lf %lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca double
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %8
8: ; preds = %50, %25, %0
%9 = load i32, i32* %2
%10 = add nsw i32 %9, -1
store i32 %10, i32* %2
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %51
12: ; preds = %8
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %6)
%15 = load double, double* %6
%16 = fcmp oeq double %15, 1.000000e+00
br i1 %16, label %17, label %26
17: ; preds = %12
%18 = load i32, i32* %3
%19 = srem i32 %18, 2
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %25
23: ; preds = %17
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %21
br label %8
26: ; preds = %12
%27 = load i32, i32* %3
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %50
31: ; preds = %26
%32 = load double, double* %6
%33 = fmul double 1.000000e+09, %32
%34 = load double, double* %6
%35 = fneg double %34
%36 = load i32, i32* %3
%37 = sub nsw i32 %36, 1
%38 = call i32 @pow(double %35, i32 %37)
%39 = sub nsw i32 1, %38
%40 = sitofp i32 %39 to double
%41 = fmul double %33, %40
%42 = load double, double* %6
%43 = fadd double 1.000000e+00, %42
%44 = fdiv double %41, %43
store double %44, double* %5
%45 = load double, double* %5
%46 = fsub double 1.000000e+09, %45
store double %46, double* %4
%47 = load double, double* %4
%48 = load double, double* %5
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), double %47, double %48)
br label %50
50: ; preds = %31, %29
br label %8
51: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.4 = [9 x i8] c"%lf %lf\0A\00"
@str.5 = [17 x i8] c"1000000000.0 0.0\00"
@str.6 = [17 x i8] c"0.0 1000000000.0\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast double* %3 to i8*
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = add nsw i32 %8, -1
store i32 %9, i32* %1
%10 = icmp eq i32 %8, 0
br i1 %10, label %45, label %11
11: ; preds = %0, %24
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %3)
%14 = load double, double* %3
%15 = fcmp oeq double %14, 1.000000e+00
%16 = load i32, i32* %2
br i1 %15, label %17, label %28
17: ; preds = %11
%18 = and i32 %16, 1
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.6, i64 0, i64 0))
br label %24
22: ; preds = %17
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
br label %24
24: ; preds = %30, %32, %20, %22
%25 = load i32, i32* %1
%26 = add nsw i32 %25, -1
store i32 %26, i32* %1
%27 = icmp eq i32 %25, 0
br i1 %27, label %45, label %11
28: ; preds = %11
%29 = icmp eq i32 %16, 1
br i1 %29, label %30, label %32
30: ; preds = %28
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
br label %24
32: ; preds = %28
%33 = fmul double %14, 1.000000e+09
%34 = fneg double %14
%35 = add nsw i32 %16, -1
%36 = call i32 @pow(double %34, i32 %35)
%37 = sub nsw i32 1, %36
%38 = sitofp i32 %37 to double
%39 = fmul double %33, %38
%40 = load double, double* %3
%41 = fadd double %40, 1.000000e+00
%42 = fdiv double %39, %41
%43 = fsub double 1.000000e+09, %42
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), double %43, double %42)
br label %24
45: ; preds = %24, %0
ret i32 0
}