• + 0 comments
    #include <stdio.h>
    #include <math.h>
    #include <stdlib.h>
    
    int closest_multiple(int ab, int x) {
        int quotient = ab / x;
        int lower = quotient * x;
        int upper = (quotient + 1) * x;
        int diff_lower = abs(ab - lower);
        int diff_upper = abs(ab - upper);
        if (diff_lower < diff_upper) {
            return lower;
        } else {
            return upper;
        }
    }
    
    int main() {
        int T;
        scanf("%d", &T);
        while (T--) {
            long long a, b, x;
            scanf("%lld %lld %lld", &a, &b, &x);
            long long ab;
            if (b >= 0) {
                ab = pow(a, b);
            } else {
                ab = round(pow(a, b));
            }
            printf("%d\n", closest_multiple(ab, x));
        }    
        return 0;
    }