#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int a, b; scanf("%d %d", &a, &b);
int ans = a;
while ( b > 10000000 ) { b -= 1000000; ans += 1000000; }
while ( b < -10000000 ) { b += 1000000; ans -= 1000000; }
while ( b > 0 ) { b-- ; ans++ ; }
while ( b < 0 ) { b++ ; ans-- ; }
printf("%d\n", ans);
}
return 0;
}