// codesnip-guard: main
fn main() {
    #![allow(unused_imports, unused_macros)]
    prepare_io!(_in_buf, scanner, _out);
    macro_rules ! print { ($ ($ arg : tt) *) => (:: std :: write ! (_out , $ ($ arg) *) . expect ("io error")) }
    macro_rules ! println { ($ ($ arg : tt) *) => (:: std :: writeln ! (_out , $ ($ arg) *) . expect ("io error")) }
    scan!(scanner, t);
    for _ in 0..t {
        scan!(scanner, n, k);
        println!("{}", M::from(n).pow(k));
    }
}
pub type M = mint_basic::MInt1000000007;
#[macro_export]
macro_rules! prepare_io {
    ($ in_buf : ident , $ scanner : ident , $ out : ident) => {
        use std::io::{stdout, BufWriter, Write as _};
        let $in_buf = read_stdin_all_unchecked();
        let mut $scanner = Scanner::new(&$in_buf);
        let $out = stdout();
        let mut $out = BufWriter::new($out.lock());
    };
}
// codesnip-guard: _echo
pub fn echo<T: std::fmt::Display>(
    mut writer: impl std::io::Write,
    iter: impl IntoIterator<Item = T>,
    sep: impl std::fmt::Display,
) -> std::io::Result<()> {
    let mut iter = iter.into_iter();
    if let Some(item) = iter.next() {
        write!(writer, "{}", item)?;
    }
    for item in iter {
        write!(writer, "{}{}", sep, item)?;
    }
    writeln!(writer)
}
// codesnip-guard: scanner
pub fn read_stdin_all_unchecked() -> String {
    use std::io::Read as _;
    let mut buf = Vec::new();
    std::io::stdin().read_to_end(&mut buf).expect("io error");
    unsafe { String::from_utf8_unchecked(buf) }
}
pub fn read_stdin_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).expect("io error");
    s
}
pub trait IterScan: Sized {
    type Output;
    fn scan<'a, I: Iterator<Item = &'a str>>(iter: &mut I) -> Option<Self::Output>;
}
pub trait MarkedIterScan: Sized {
    type Output;
    fn mscan<'a, I: Iterator<Item = &'a str>>(self, iter: &mut I) -> Option<Self::Output>;
}
#[derive(Clone, Debug)]
pub struct Scanner<'a> {
    iter: std::str::SplitAsciiWhitespace<'a>,
}
mod scanner_impls {
    use super::*;
    impl<'a> Scanner<'a> {
        #[inline]
        pub fn new(s: &'a str) -> Self {
            let iter = s.split_ascii_whitespace();
            Self { iter }
        }
        #[inline]
        pub fn scan<T: IterScan>(&mut self) -> <T as IterScan>::Output {
            <T as IterScan>::scan(&mut self.iter).expect("scan error")
        }
        #[inline]
        pub fn mscan<T: MarkedIterScan>(&mut self, marker: T) -> <T as MarkedIterScan>::Output {
            marker.mscan(&mut self.iter).expect("scan error")
        }
        #[inline]
        pub fn scan_vec<T: IterScan>(&mut self, size: usize) -> Vec<<T as IterScan>::Output> {
            (0..size)
                .map(|_| <T as IterScan>::scan(&mut self.iter).expect("scan error"))
                .collect()
        }
        #[inline]
        pub fn iter<'b, T: IterScan>(&'b mut self) -> ScannerIter<'a, 'b, T> {
            ScannerIter {
                inner: self,
                _marker: std::marker::PhantomData,
            }
        }
    }
    macro_rules ! iter_scan_impls { ($ ($ t : ty) *) => { $ (impl IterScan for $ t { type Output = Self ; # [inline] fn scan <'a , I : Iterator < Item = &'a str >> (iter : & mut I) -> Option < Self > { iter . next () ?. parse ::<$ t > () . ok () } }) * } ; }
    iter_scan_impls ! (char u8 u16 u32 u64 usize i8 i16 i32 i64 isize f32 f64 u128 i128 String);
    macro_rules ! iter_scan_tuple_impl { ($ ($ T : ident) *) => { impl <$ ($ T : IterScan) ,*> IterScan for ($ ($ T ,) *) { type Output = ($ (<$ T as IterScan >:: Output ,) *) ; # [inline] fn scan <'a , It : Iterator < Item = &'a str >> (_iter : & mut It) -> Option < Self :: Output > { Some (($ (<$ T as IterScan >:: scan (_iter) ?,) *)) } } } ; }
    iter_scan_tuple_impl!();
    iter_scan_tuple_impl!(A);
    iter_scan_tuple_impl ! (A B);
    iter_scan_tuple_impl ! (A B C);
    iter_scan_tuple_impl ! (A B C D);
    iter_scan_tuple_impl ! (A B C D E);
    iter_scan_tuple_impl ! (A B C D E F);
    iter_scan_tuple_impl ! (A B C D E F G);
    iter_scan_tuple_impl ! (A B C D E F G H);
    iter_scan_tuple_impl ! (A B C D E F G H I);
    iter_scan_tuple_impl ! (A B C D E F G H I J);
    iter_scan_tuple_impl ! (A B C D E F G H I J K);
    pub struct ScannerIter<'a, 'b, T> {
        inner: &'b mut Scanner<'a>,
        _marker: std::marker::PhantomData<fn() -> T>,
    }
    impl<'a, 'b, T: IterScan> Iterator for ScannerIter<'a, 'b, T> {
        type Item = <T as IterScan>::Output;
        #[inline]
        fn next(&mut self) -> Option<Self::Item> {
            <T as IterScan>::scan(&mut self.inner.iter)
        }
    }
}
#[derive(Debug, Copy, Clone)]
pub struct Usize1;
#[derive(Debug, Copy, Clone)]
pub struct CharWithBase(pub char);
#[derive(Debug, Copy, Clone)]
pub struct Chars;
#[derive(Debug, Copy, Clone)]
pub struct CharsWithBase(pub char);
#[derive(Debug, Copy, Clone)]
pub struct Collect<T: IterScan, B: std::iter::FromIterator<<T as IterScan>::Output>> {
    size: usize,
    _marker: std::marker::PhantomData<fn() -> (T, B)>,
}
mod marker_impls {
    use super::*;
    use std::{iter::FromIterator, marker::PhantomData};
    impl IterScan for Usize1 {
        type Output = usize;
        #[inline]
        fn scan<'a, I: Iterator<Item = &'a str>>(iter: &mut I) -> Option<Self::Output> {
            <usize as IterScan>::scan(iter)?.checked_sub(1)
        }
    }
    impl MarkedIterScan for CharWithBase {
        type Output = usize;
        #[inline]
        fn mscan<'a, I: Iterator<Item = &'a str>>(self, iter: &mut I) -> Option<Self::Output> {
            Some((<char as IterScan>::scan(iter)? as u8 - self.0 as u8) as usize)
        }
    }
    impl IterScan for Chars {
        type Output = Vec<char>;
        #[inline]
        fn scan<'a, I: Iterator<Item = &'a str>>(iter: &mut I) -> Option<Self::Output> {
            Some(iter.next()?.chars().collect())
        }
    }
    impl MarkedIterScan for CharsWithBase {
        type Output = Vec<usize>;
        #[inline]
        fn mscan<'a, I: Iterator<Item = &'a str>>(self, iter: &mut I) -> Option<Self::Output> {
            Some(
                iter.next()?
                    .chars()
                    .map(|c| (c as u8 - self.0 as u8) as usize)
                    .collect(),
            )
        }
    }
    impl<T: IterScan, B: FromIterator<<T as IterScan>::Output>> Collect<T, B> {
        pub fn new(size: usize) -> Self {
            Self {
                size,
                _marker: PhantomData,
            }
        }
    }
    impl<T: IterScan, B: FromIterator<<T as IterScan>::Output>> MarkedIterScan for Collect<T, B> {
        type Output = B;
        #[inline]
        fn mscan<'a, I: Iterator<Item = &'a str>>(self, iter: &mut I) -> Option<Self::Output> {
            Some(
                (0..self.size)
                    .map(|_| <T as IterScan>::scan(iter).expect("scan error"))
                    .collect::<B>(),
            )
        }
    }
}
#[macro_export]
macro_rules ! scan_value { ($ scanner : expr , ($ ($ t : tt) ,*)) => { ($ ($ crate :: scan_value ! ($ scanner , $ t)) ,*) } ; ($ scanner : expr , [$ t : tt ; $ len : expr]) => { (0 ..$ len) . map (| _ | $ crate :: scan_value ! ($ scanner , $ t)) . collect ::< Vec < _ >> () } ; ($ scanner : expr , [$ t : ty ; $ len : expr]) => { $ scanner . scan_vec ::<$ t > ($ len) } ; ($ scanner : expr , [$ t : ty]) => { $ scanner . iter ::<$ t > () } ; ($ scanner : expr , { $ e : expr }) => { $ scanner . mscan ($ e) } ; ($ scanner : expr , $ t : ty) => { $ scanner . scan ::<$ t > () } ; }
#[macro_export]
macro_rules ! scan { ($ scanner : expr) => { } ; ($ scanner : expr ,) => { } ; ($ scanner : expr , mut $ var : tt : $ t : tt) => { let mut $ var = $ crate :: scan_value ! ($ scanner , $ t) ; } ; ($ scanner : expr , $ var : tt : $ t : tt) => { let $ var = $ crate :: scan_value ! ($ scanner , $ t) ; } ; ($ scanner : expr , mut $ var : tt : $ t : tt , $ ($ rest : tt) *) => { let mut $ var = $ crate :: scan_value ! ($ scanner , $ t) ; scan ! ($ scanner , $ ($ rest) *) } ; ($ scanner : expr , $ var : tt : $ t : tt , $ ($ rest : tt) *) => { let $ var = $ crate :: scan_value ! ($ scanner , $ t) ; scan ! ($ scanner , $ ($ rest) *) } ; ($ scanner : expr , mut $ var : tt) => { let mut $ var = $ crate :: scan_value ! ($ scanner , usize) ; } ; ($ scanner : expr , $ var : tt) => { let $ var = $ crate :: scan_value ! ($ scanner , usize) ; } ; ($ scanner : expr , mut $ var : tt , $ ($ rest : tt) *) => { let mut $ var = $ crate :: scan_value ! ($ scanner , usize) ; scan ! ($ scanner , $ ($ rest) *) } ; ($ scanner : expr , $ var : tt , $ ($ rest : tt) *) => { let $ var = $ crate :: scan_value ! ($ scanner , usize) ; scan ! ($ scanner , $ ($ rest) *) } ; }
// codesnip-guard: MInt
pub mod mint_basic {
    use super::*;
    #[macro_export]
    macro_rules ! define_basic_mintbase { ($ name : ident , $ m : expr , $ basety : ty , $ signedty : ty , $ upperty : ty , [$ ($ unsigned : ty) ,*] , [$ ($ signed : ty) ,*]) => { pub struct $ name ; impl MIntBase for $ name { type Inner = $ basety ; # [inline] fn get_mod () -> Self :: Inner { $ m } # [inline] fn mod_zero () -> Self :: Inner { 0 } # [inline] fn mod_one () -> Self :: Inner { 1 } # [inline] fn mod_add (x : Self :: Inner , y : Self :: Inner) -> Self :: Inner { let z = x + y ; let m = Self :: get_mod () ; if z >= m { z - m } else { z } } # [inline] fn mod_sub (x : Self :: Inner , y : Self :: Inner) -> Self :: Inner { if x < y { x + Self :: get_mod () - y } else { x - y } } # [inline] fn mod_mul (x : Self :: Inner , y : Self :: Inner) -> Self :: Inner { (x as $ upperty * y as $ upperty % Self :: get_mod () as $ upperty) as $ basety } # [inline] fn mod_div (x : Self :: Inner , y : Self :: Inner) -> Self :: Inner { Self :: mod_mul (x , Self :: mod_inv (y)) } # [inline] fn mod_neg (x : Self :: Inner) -> Self :: Inner { if x == 0 { 0 } else { Self :: get_mod () - x } } fn mod_inv (x : Self :: Inner) -> Self :: Inner { let p = Self :: get_mod () as $ signedty ; let (mut a , mut b) = (x as $ signedty , p) ; let (mut u , mut x) = (1 , 0) ; while a != 0 { let k = b / a ; x -= k * u ; b -= k * a ; std :: mem :: swap (& mut x , & mut u) ; std :: mem :: swap (& mut b , & mut a) ; } (if x < 0 { x + p } else { x }) as _ } } $ (impl MIntConvert <$ unsigned > for $ name { # [inline] fn from (x : $ unsigned) -> Self :: Inner { (x % < Self as MIntBase >:: get_mod () as $ unsigned) as $ basety } # [inline] fn into (x : Self :: Inner) -> $ unsigned { x as $ unsigned } # [inline] fn mod_into () -> $ unsigned { < Self as MIntBase >:: get_mod () as $ unsigned } }) * $ (impl MIntConvert <$ signed > for $ name { # [inline] fn from (x : $ signed) -> Self :: Inner { let x = x % < Self as MIntBase >:: get_mod () as $ signed ; if x < 0 { (x + < Self as MIntBase >:: get_mod () as $ signed) as $ basety } else { x as $ basety } } # [inline] fn into (x : Self :: Inner) -> $ signed { x as $ signed } # [inline] fn mod_into () -> $ signed { < Self as MIntBase >:: get_mod () as $ signed } }) * } ; }
    #[macro_export]
    macro_rules ! define_basic_mint32 { ($ ([$ name : ident , $ m : expr , $ mint_name : ident]) ,*) => { $ (crate :: define_basic_mintbase ! ($ name , $ m , u32 , i32 , u64 , [u32 , u64 , u128 , usize] , [i32 , i64 , i128 , isize]) ; pub type $ mint_name = MInt <$ name >;) * } ; }
    define_basic_mint32!(
        [Modulo998244353, 998_244_353, MInt998244353],
        [Modulo1000000007, 1_000_000_007, MInt1000000007],
        [Modulo1000000009, 1_000_000_009, MInt1000000009],
        [
            DynModuloU32,
            DYN_MODULUS_U32.with(|cell| unsafe { *cell.get() }),
            DynMIntU32
        ]
    );
    thread_local ! (static DYN_MODULUS_U32 : std :: cell :: UnsafeCell < u32 > = std :: cell :: UnsafeCell :: new (1_000_000_007));
    impl DynModuloU32 {
        pub fn set_mod(m: u32) {
            DYN_MODULUS_U32.with(|cell| unsafe { *cell.get() = m })
        }
    }
    thread_local ! (static DYN_MODULUS_U64 : std :: cell :: UnsafeCell < u64 > = std :: cell :: UnsafeCell :: new (1_000_000_007));
    define_basic_mintbase!(
        DynModuloU64,
        DYN_MODULUS_U64.with(|cell| unsafe { *cell.get() }),
        u64,
        i64,
        u128,
        [u64, u128, usize],
        [i64, i128, isize]
    );
    impl DynModuloU64 {
        pub fn set_mod(m: u64) {
            DYN_MODULUS_U64.with(|cell| unsafe { *cell.get() = m })
        }
    }
    pub type DynMIntU64 = MInt<DynModuloU64>;
    pub struct Modulo2;
    impl MIntBase for Modulo2 {
        type Inner = u32;
        #[inline]
        fn get_mod() -> Self::Inner {
            2
        }
        #[inline]
        fn mod_zero() -> Self::Inner {
            0
        }
        #[inline]
        fn mod_one() -> Self::Inner {
            1
        }
        #[inline]
        fn mod_add(x: Self::Inner, y: Self::Inner) -> Self::Inner {
            x ^ y
        }
        #[inline]
        fn mod_sub(x: Self::Inner, y: Self::Inner) -> Self::Inner {
            x ^ y
        }
        #[inline]
        fn mod_mul(x: Self::Inner, y: Self::Inner) -> Self::Inner {
            x | y
        }
        #[inline]
        fn mod_div(x: Self::Inner, y: Self::Inner) -> Self::Inner {
            assert_ne!(y, 0);
            x
        }
        #[inline]
        fn mod_neg(x: Self::Inner) -> Self::Inner {
            x
        }
        #[inline]
        fn mod_inv(x: Self::Inner) -> Self::Inner {
            assert_ne!(x, 0);
            x
        }
        #[inline]
        fn mod_pow(x: Self::Inner, y: usize) -> Self::Inner {
            if y == 0 {
                1
            } else {
                x
            }
        }
    }
    macro_rules ! impl_to_mint_base_for_modulo2 { ($ name : ident , $ basety : ty , [$ ($ t : ty) ,*]) => { $ (impl MIntConvert <$ t > for $ name { # [inline] fn from (x : $ t) -> Self :: Inner { (x & 1) as $ basety } # [inline] fn into (x : Self :: Inner) -> $ t { x as $ t } # [inline] fn mod_into () -> $ t { 1 } }) * } ; }
    impl_to_mint_base_for_modulo2!(
        Modulo2,
        u32,
        [u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize]
    );
    pub type MInt2 = MInt<Modulo2>;
}
// codesnip-guard: MIntBase
#[repr(transparent)]
pub struct MInt<M>
where
    M: MIntBase,
{
    x: M::Inner,
    _marker: std::marker::PhantomData<fn() -> M>,
}
pub trait MIntBase {
    type Inner: Sized + Copy + Eq + std::fmt::Debug + std::hash::Hash;
    fn get_mod() -> Self::Inner;
    fn mod_zero() -> Self::Inner;
    fn mod_one() -> Self::Inner;
    fn mod_add(x: Self::Inner, y: Self::Inner) -> Self::Inner;
    fn mod_sub(x: Self::Inner, y: Self::Inner) -> Self::Inner;
    fn mod_mul(x: Self::Inner, y: Self::Inner) -> Self::Inner;
    fn mod_div(x: Self::Inner, y: Self::Inner) -> Self::Inner;
    fn mod_neg(x: Self::Inner) -> Self::Inner;
    fn mod_inv(x: Self::Inner) -> Self::Inner;
    fn mod_pow(x: Self::Inner, y: usize) -> Self::Inner {
        let (mut x, mut y, mut z) = (x, y, Self::mod_one());
        while y > 0 {
            if y & 1 == 1 {
                z = Self::mod_mul(z, x);
            }
            x = Self::mod_mul(x, x);
            y >>= 1;
        }
        z
    }
}
pub trait MIntConvert<T = <Self as MIntBase>::Inner>: MIntBase {
    fn from(x: T) -> <Self as MIntBase>::Inner;
    fn into(x: <Self as MIntBase>::Inner) -> T;
    fn mod_into() -> T;
}
mod mint_base {
    use super::*;
    use std::{
        fmt::{self, Debug, Display},
        hash::{Hash, Hasher},
        iter::{Product, Sum},
        marker::PhantomData,
        ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign},
        str::FromStr,
    };
    impl<M> MInt<M>
    where
        M: MIntConvert,
    {
        #[inline]
        pub fn new(x: M::Inner) -> Self {
            Self::new_unchecked(<M as MIntConvert<M::Inner>>::from(x))
        }
        #[inline]
        pub fn inner(self) -> M::Inner {
            <M as MIntConvert<M::Inner>>::into(self.x)
        }
    }
    impl<M> MInt<M>
    where
        M: MIntBase,
    {
        #[inline]
        pub fn new_unchecked(x: M::Inner) -> Self {
            Self {
                x,
                _marker: PhantomData,
            }
        }
        #[inline]
        pub fn get_mod() -> M::Inner {
            M::get_mod()
        }
        #[inline]
        pub fn pow(self, y: usize) -> Self {
            Self::new_unchecked(M::mod_pow(self.x, y))
        }
        #[inline]
        pub fn inv(self) -> Self {
            Self::new_unchecked(M::mod_inv(self.x))
        }
    }
    impl<M> Clone for MInt<M>
    where
        M: MIntBase,
    {
        #[inline]
        fn clone(&self) -> Self {
            Self {
                x: Clone::clone(&self.x),
                _marker: PhantomData,
            }
        }
    }
    impl<M> Copy for MInt<M> where M: MIntBase {}
    impl<M> Debug for MInt<M>
    where
        M: MIntBase,
    {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            Debug::fmt(&self.x, f)
        }
    }
    impl<M> Default for MInt<M>
    where
        M: MIntBase,
    {
        #[inline]
        fn default() -> Self {
            <Self as Zero>::zero()
        }
    }
    impl<M> PartialEq for MInt<M>
    where
        M: MIntBase,
    {
        #[inline]
        fn eq(&self, other: &Self) -> bool {
            PartialEq::eq(&self.x, &other.x)
        }
    }
    impl<M> Eq for MInt<M> where M: MIntBase {}
    impl<M> Hash for MInt<M>
    where
        M: MIntBase,
    {
        #[inline]
        fn hash<H: Hasher>(&self, state: &mut H) {
            Hash::hash(&self.x, state)
        }
    }
    macro_rules ! impl_mint_from { ($ ($ t : ty) ,*) => { $ (impl < M > From <$ t > for MInt < M > where M : MIntConvert <$ t >, { # [inline] fn from (x : $ t) -> Self { Self :: new_unchecked (< M as MIntConvert <$ t >>:: from (x)) } } impl < M > From < MInt < M >> for $ t where M : MIntConvert <$ t >, { # [inline] fn from (x : MInt < M >) -> $ t { < M as MIntConvert <$ t >>:: into (x . x) } }) * } ; }
    impl_mint_from!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
    impl<M> Zero for MInt<M>
    where
        M: MIntBase,
    {
        #[inline]
        fn zero() -> Self {
            Self::new_unchecked(M::mod_zero())
        }
    }
    impl<M> One for MInt<M>
    where
        M: MIntBase,
    {
        #[inline]
        fn one() -> Self {
            Self::new_unchecked(M::mod_one())
        }
    }
    impl<M> Add for MInt<M>
    where
        M: MIntBase,
    {
        type Output = Self;
        #[inline]
        fn add(self, rhs: Self) -> Self::Output {
            Self::new_unchecked(M::mod_add(self.x, rhs.x))
        }
    }
    impl<M> Sub for MInt<M>
    where
        M: MIntBase,
    {
        type Output = Self;
        #[inline]
        fn sub(self, rhs: Self) -> Self::Output {
            Self::new_unchecked(M::mod_sub(self.x, rhs.x))
        }
    }
    impl<M> Mul for MInt<M>
    where
        M: MIntBase,
    {
        type Output = Self;
        #[inline]
        fn mul(self, rhs: Self) -> Self::Output {
            Self::new_unchecked(M::mod_mul(self.x, rhs.x))
        }
    }
    impl<M> Div for MInt<M>
    where
        M: MIntBase,
    {
        type Output = Self;
        #[inline]
        fn div(self, rhs: Self) -> Self::Output {
            Self::new_unchecked(M::mod_div(self.x, rhs.x))
        }
    }
    impl<M> Neg for MInt<M>
    where
        M: MIntBase,
    {
        type Output = Self;
        #[inline]
        fn neg(self) -> Self::Output {
            Self::new_unchecked(M::mod_neg(self.x))
        }
    }
    impl<M> Sum for MInt<M>
    where
        M: MIntBase,
    {
        #[inline]
        fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
            iter.fold(<Self as Zero>::zero(), Add::add)
        }
    }
    impl<M> Product for MInt<M>
    where
        M: MIntBase,
    {
        #[inline]
        fn product<I: Iterator<Item = Self>>(iter: I) -> Self {
            iter.fold(<Self as One>::one(), Mul::mul)
        }
    }
    impl<'a, M: 'a> Sum<&'a MInt<M>> for MInt<M>
    where
        M: MIntBase,
    {
        #[inline]
        fn sum<I: Iterator<Item = &'a Self>>(iter: I) -> Self {
            iter.fold(<Self as Zero>::zero(), Add::add)
        }
    }
    impl<'a, M: 'a> Product<&'a MInt<M>> for MInt<M>
    where
        M: MIntBase,
    {
        #[inline]
        fn product<I: Iterator<Item = &'a Self>>(iter: I) -> Self {
            iter.fold(<Self as One>::one(), Mul::mul)
        }
    }
    impl<M> Display for MInt<M>
    where
        M: MIntConvert,
        M::Inner: Display,
    {
        fn fmt<'a>(&self, f: &mut fmt::Formatter<'a>) -> Result<(), fmt::Error> {
            write!(f, "{}", self.inner())
        }
    }
    impl<M> FromStr for MInt<M>
    where
        M: MIntConvert,
        M::Inner: FromStr,
    {
        type Err = <M::Inner as FromStr>::Err;
        #[inline]
        fn from_str(s: &str) -> Result<Self, Self::Err> {
            s.parse::<M::Inner>().map(Self::new)
        }
    }
    impl<M> IterScan for MInt<M>
    where
        M: MIntConvert,
        M::Inner: FromStr,
    {
        type Output = Self;
        #[inline]
        fn scan<'a, I: Iterator<Item = &'a str>>(iter: &mut I) -> Option<Self::Output> {
            iter.next()?.parse::<MInt<M>>().ok()
        }
    }
    macro_rules! impl_mint_ref_binop {
        ($ imp : ident , $ method : ident , $ t : ty) => {
            impl<M> $imp<$t> for &$t
            where
                M: MIntBase,
            {
                type Output = <$t as $imp<$t>>::Output;
                #[inline]
                fn $method(self, other: $t) -> <$t as $imp<$t>>::Output {
                    $imp::$method(*self, other)
                }
            }
            impl<M> $imp<&$t> for $t
            where
                M: MIntBase,
            {
                type Output = <$t as $imp<$t>>::Output;
                #[inline]
                fn $method(self, other: &$t) -> <$t as $imp<$t>>::Output {
                    $imp::$method(self, *other)
                }
            }
            impl<M> $imp<&$t> for &$t
            where
                M: MIntBase,
            {
                type Output = <$t as $imp<$t>>::Output;
                #[inline]
                fn $method(self, other: &$t) -> <$t as $imp<$t>>::Output {
                    $imp::$method(*self, *other)
                }
            }
        };
    }
    impl_mint_ref_binop!(Add, add, MInt<M>);
    impl_mint_ref_binop!(Sub, sub, MInt<M>);
    impl_mint_ref_binop!(Mul, mul, MInt<M>);
    impl_mint_ref_binop!(Div, div, MInt<M>);
    macro_rules! impl_mint_ref_unop {
        ($ imp : ident , $ method : ident , $ t : ty) => {
            impl<M> $imp for &$t
            where
                M: MIntBase,
            {
                type Output = <$t as $imp>::Output;
                #[inline]
                fn $method(self) -> <$t as $imp>::Output {
                    $imp::$method(*self)
                }
            }
        };
    }
    impl_mint_ref_unop!(Neg, neg, MInt<M>);
    macro_rules! impl_mint_ref_op_assign {
        ($ imp : ident , $ method : ident , $ t : ty , $ fromimp : ident , $ frommethod : ident) => {
            impl<M> $imp<$t> for $t
            where
                M: MIntBase,
            {
                #[inline]
                fn $method(&mut self, rhs: $t) {
                    *self = $fromimp::$frommethod(*self, rhs);
                }
            }
            impl<M> $imp<&$t> for $t
            where
                M: MIntBase,
            {
                #[inline]
                fn $method(&mut self, other: &$t) {
                    $imp::$method(self, *other);
                }
            }
        };
    }
    impl_mint_ref_op_assign!(AddAssign, add_assign, MInt<M>, Add, add);
    impl_mint_ref_op_assign!(SubAssign, sub_assign, MInt<M>, Sub, sub);
    impl_mint_ref_op_assign!(MulAssign, mul_assign, MInt<M>, Mul, mul);
    impl_mint_ref_op_assign!(DivAssign, div_assign, MInt<M>, Div, div);
}
// codesnip-guard: zero_one
pub trait Zero: Sized {
    fn zero() -> Self;
    #[inline]
    fn is_zero(&self) -> bool
    where
        Self: PartialEq,
    {
        self == &Self::zero()
    }
    #[inline]
    fn set_zero(&mut self) {
        *self = Self::zero();
    }
}
pub trait One: Sized {
    fn one() -> Self;
    #[inline]
    fn is_one(&self) -> bool
    where
        Self: PartialEq,
    {
        self == &Self::one()
    }
    #[inline]
    fn set_one(&mut self) {
        *self = Self::one();
    }
}
macro_rules ! zero_one_impls { ($ ({ $ Trait : ident $ method : ident $ ($ t : ty) *, $ e : expr }) *) => { $ ($ (impl $ Trait for $ t { fn $ method () -> Self { $ e } }) *) * } ; }
zero_one_impls ! ({ Zero zero u8 u16 u32 u64 usize i8 i16 i32 i64 isize u128 i128 , 0 } { Zero zero f32 f64 , 0. } { One one u8 u16 u32 u64 usize i8 i16 i32 i64 isize u128 i128 , 1 } { One one f32 f64 , 1. });


use std::io::{self, Write};

const MOD: i64 = 1e9 as i64 + 7;

fn pow(mut a: i64, mut b: i64) -> i64 {
    let mut ans: i64 = 1;
    while b > 0 {
        if b & 1 == 1 {
            ans = (ans as i64 * a as i64) % MOD;
        }
        a = (a * a) % MOD;
        b >>= 1;
    }
    ans
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut sc = cf_scanner::Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());

    for _ in 0..sc.next() {
        writeln!(out, "{}", pow(sc.next(), sc.next())).unwrap();
    }
}

#[allow(dead_code)]
mod cf_scanner {
    use std::io;
    use std::str::{FromStr, SplitAsciiWhitespace};

    pub struct Scanner<R> {
        reader: R,
        buf_str: Vec<u8>,
        buf_iter: SplitAsciiWhitespace<'static>,
    }

    impl<R: io::BufRead> Scanner<R> {
        pub fn new(reader: R) -> Scanner<R> {
            Scanner {
                reader,
                buf_str: Vec::new(),
                buf_iter: "".split_ascii_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            loop {
                if let Some(token) = self.buf_iter.next() {
                    return token.parse().ok().expect("Failed parse");
                }
                self.buf_str.clear();
                self.reader
                    .read_until(b'\n', &mut self.buf_str)
                    .expect("Failed read");
                self.buf_iter = unsafe {
                    let slice = std::str::from_utf8_unchecked(&self.buf_str);
                    std::mem::transmute(slice.split_ascii_whitespace())
                }
            }
        }
    }
}


#[allow(dead_code)]
fn solve(read: &mut snio::Reader<std::io::StdinLock<'_>>) {
    let n = read.usize();
    let k = read.i64();
    //let mut ans = Vec::new();
    //xans.push(base);
    set_mod_int(1e9 as i64 + 7);
    let mut ans = mod_int::ModInt::new(n as i64);
    if n == 0 {
        println!("1");
    }else{
        ans = ans.pow(k);
        println!("{}",ans.value());
    }
}

//use proconio::input;
fn main() {
    let t = std::io::stdin();
    let mut read = snio::Reader::new(t.lock());
    let n = read.i64();
    for _ in 0..n {
        solve(&mut read);
    }
   // let mut rec = Vec::new();
}

#[allow(dead_code)]
pub mod snio {
    pub struct Reader<R: std::io::BufRead> {
        reader: R,
        buf: std::collections::VecDeque<String>,
    }

    impl<R: std::io::BufRead> Reader<R> {
        pub fn new(reader: R) -> Self {
            Self {
                reader,
                buf: std::collections::VecDeque::new(),
            }
        }
        fn load(&mut self) {
            while self.buf.is_empty() {
                let mut s = String::new();
                let length = self.reader.read_line(&mut s).unwrap();
                if length == 0 {
                    break;
                }
                self.buf.extend(s.split_whitespace().map(|s| s.to_owned()));
            }
        }
        pub fn string(&mut self) -> String {
            self.load();
            self.buf.pop_front().unwrap_or_else(|| panic!("input ended"))
        }
        pub fn char(&mut self) -> char {
            let string = self.string();
            let mut chars = string.chars();
            let res = chars.next().unwrap();
            assert!(chars.next().is_none(), "invalid input!");
            res
        }
        pub fn chars(&mut self) -> Vec<char> {
            self.read::<String>().chars().collect()
        }
        pub fn read<T: std::str::FromStr>(&mut self) -> T
            where
                <T as ::std::str::FromStr>::Err: ::std::fmt::Debug,
        {
            self.string().parse::<T>().expect("Failed to parse the input.")
        }
    }
    macro_rules! definition_of_reader_of_numbers {
            ($($ty:tt,)*) => {
                impl <R:std::io::BufRead> Reader<R> {
                    $(
                    #[inline]
                    pub fn $ty (&mut self) -> $ty {
                        self.read::<$ty>()
                    }
                    )*
                }
            }
        }
    definition_of_reader_of_numbers! {
        u8,u16,u32,u64,usize,
        i8,i16,i32,i64,isize,
    }
}

use crate::mod_int::{set_mod_int,ModInt};
//from https://github.com/kenkoooo/competitive-programming-rs/blob/master/src/math/mod_int.rs
pub mod mod_int {
    use std::cell::RefCell;
    use std::ops::{Add,AddAssign,Div,DivAssign,Mul,MulAssign,Sub,SubAssign};

    type InternalNum = i64;
    thread_local!(
        static MOD: RefCell<InternalNum> = RefCell::new(0);//0という値でRefCellを生成
        );

    pub fn set_mod_int<T>(v:T)
    where
        InternalNum: From<T>,
    {
        MOD.with(|x| x.replace(InternalNum::from(v)));
    }

    fn modulo() -> InternalNum {
        MOD.with(|x| *x.borrow())
    }

    pub struct ModInt(InternalNum);//tuple構造体

    impl Clone for ModInt {
        fn clone(&self) -> Self {
            Self(self.0)
        }
    }
    impl Copy for ModInt {}

    impl ModInt {
        pub fn new<T>(v:T) -> Self
        where
            InternalNum: From<T>,
        {
            let mut v = InternalNum::from(v);
            let m = modulo();
            if v >= m {
                v %= m;
            }
            Self(v)
        }

        pub fn internal_pow(&self, mut e: InternalNum) -> Self {
            let mut result = 1;
            let mut cur = self.0;
            let modulo = modulo();
            while e > 0 {
                if e & 1 == 1 {
                    result *= cur;
                    result %= modulo;
                }
                e >>= 1;
                cur = (cur * cur) % modulo;
            }
            Self(result)
        }

        pub fn pow<T>(&self , e:T) -> Self
        where
            InternalNum: From<T>,
        {
            self.internal_pow(InternalNum::from(e))
        }

        pub fn value(&self) -> InternalNum {
            self.0
        }
    }

    impl From<ModInt> for InternalNum {
        fn from(m:ModInt) -> Self {
            m.value()
        }
    }

    impl<T> AddAssign<T> for ModInt
    where
        InternalNum: From<T>,
    {
        fn add_assign(&mut self,rhs:T) {
            let mut rhs = InternalNum::from(rhs);
            let m = modulo();
            if rhs >= m {
                rhs %= m;
            }

            self.0 += rhs;
            if self.0 >= m {
                self.0 -= m;
            }
        }
    }

    impl<T> Add<T> for ModInt
    where
        InternalNum: From<T>,
    {
        type Output = ModInt;
        fn add(self, rhs: T) -> Self::Output {
            let mut res = self;
            res += rhs;
            res
        }
    }

    impl<T> SubAssign<T> for ModInt
    where
        InternalNum: From<T>,
    {
        fn sub_assign(&mut self, rhs: T) {
            let mut rhs = InternalNum::from(rhs);
            let m = modulo();
            if rhs >= m {
                rhs %= m;
            }
            if rhs > 0 {
                self.0 += m - rhs;
            }
            if self.0 >= m {
                self.0 -= m;
            }
        }
    }

    impl<T> Sub<T> for ModInt
    where
        InternalNum: From<T>,
    {
        type Output = Self;
        fn sub(self,rhs:T) -> Self::Output {
            let mut res = self;
            res -= rhs;
            res
        }
    }

    impl<T> MulAssign<T> for ModInt
    where
        InternalNum: From<T>,
    {
        fn mul_assign(&mut self, rhs: T) {
            let mut rhs = InternalNum::from(rhs);
            let m = modulo();
            if rhs >= m {
                rhs %= m;
            }
            self.0 *= rhs;
            self.0 %= m;
        }
    }

    impl<T> Mul<T> for ModInt
    where
        InternalNum: From<T>,
    {
        type Output = Self;
        fn mul(self, rhs:T) -> Self::Output {
            let mut res = self;
            res *= rhs;
            res
        }
    }

    impl<T> DivAssign<T> for ModInt
    where
        InternalNum: From<T>,
    {
        fn div_assign(&mut self, rhs:T){
            let mut rhs = InternalNum::from(rhs);
            let m = modulo();
            if rhs >= m {
                rhs %= m;
            }
            let inv = Self(rhs).internal_pow(m - 2);
            self.0 *= inv.value();
            self.0 %= m;
        }
    }

    impl<T> Div<T> for ModInt
    where
        InternalNum: From<T>,
    {
        type Output = Self;
        fn div(self, rhs: T) -> Self::Output {
            let mut res = self;
            res /= rhs;
            res
        }
    }
}

pub mod binomial_coefficient {
    use crate::mod_int::{set_mod_int,ModInt};
    pub struct BinomialCoefficient<ModInt> {
        fact:Vec<ModInt>,
        inversion:Vec<ModInt>
    }
    impl BinomialCoefficient<ModInt> {
       pub fn new(n:usize,_mod:i64) -> Self {
            set_mod_int(_mod);
            let a = ModInt::new(1);
            let mut _fact:Vec<ModInt> = vec![a;n + 1];
            let mut _inversion:Vec<ModInt> = vec![a;n + 1];
            for i in 1..=n{
                _fact[i] = _fact[i - 1] * i as i64;
            }
            _inversion[n] = _fact[n].internal_pow(_mod - 2);
            for i in (1..=n).rev(){
               _inversion[i - 1] = _inversion[i] * i as i64;
            }
        BinomialCoefficient {
            fact:_fact,
            inversion:_inversion
            }
        }
        pub fn combination(&mut self,n:i64,k:i64) -> ModInt{
            if k < 0 || k > n {
                return ModInt::new(0)
            }
            self.fact[n as usize] * self.inversion[k as usize] * self.inversion[n as usize - k as usize]

        }

        pub fn permutation(&mut self,n:i64,k:i64) -> ModInt{
            if k < 0 || k > n{
                return ModInt::new(0)
            }
            self.combination(n,k) * self.fact[k as usize]
        }
    }
}


use std::{
    fmt::Write,
    io::{prelude::*, stdin},
    iter::{self, Peekable},
};

fn main() {
    let mut input = String::new();
    stdin().read_to_string(&mut input).unwrap();

    let mut it = input
        .split_whitespace()
        .map(|s| s.parse::<u64>().unwrap());

    let t = it.next().unwrap();

    let mut output = String::new();

    let p = 1_000_000_007;

    for _ in 0..t {
        let mut n = it.next().unwrap();
        let mut k = it.next().unwrap();

        let mut ans = 1;

        for _ in 0..k {
            ans = (ans * n) % p;
        }

        writeln!(&mut output, "{}", ans).unwrap();
    }

    print!("{}", output);
}


use std::io::{BufWriter, stdin, stdout, Write};

#[derive(Default)]
struct Scanner {
    buffer: Vec<String>
}
impl Scanner {
    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            stdin().read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

fn main() {
    let mut scan = Scanner::default();
    let out = &mut BufWriter::new(stdout());

	let a = scan.next::<String>();
    let lower = a.chars().filter(|c| c.is_lowercase()).count();
    let upper = a.chars().filter(|c| c.is_uppercase()).count();

    writeln!(out, "{}", if upper > lower { a.to_uppercase() } else { a.to_lowercase() }).expect("fail");
}


fn main() {
    let mut word = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim().to_string()
    };

    let half = word.len() / 2;
    if word.chars().filter(|c| c.is_uppercase()).count() > half {
        word = word.to_uppercase();
    } else {
        word = word.to_lowercase();
    }

    println!("{}", word);
}


use std::io::{self, Read};

fn get_input() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("Failed");
    buffer
}

fn main() -> io::Result<()> {
    let mut input = get_input().trim().to_string();

    let mut count = 0;
    for c in input.chars() {
        if c.is_ascii_uppercase() {
            count += 1;
        }
    }

    if count > input.len() / 2 {
        println!("{}", input.to_uppercase());
    } else {
        println!("{}", input.to_lowercase());
    }

    Ok(())
}


// {{{ by shik

use std::io;

#[allow(dead_code)]
fn gets() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(unused_macros)]
macro_rules! R {
    ( $ty:ty, ... ) => {
        gets().split_whitespace().map(|x| x.parse::<$ty>().unwrap()).collect::<Vec<_>>()
    };
    ( $($ty:ty),* ) => {{
        let line = gets();
        let mut it = line.split_whitespace();
        ( $(it.next().unwrap().parse::<$ty>().unwrap(),)* )
    }}
}

#[allow(unused_macros)]
macro_rules! W {
    ( $x:expr ) => {{
        println!("{}", $x);
    }};
    ( $x:expr, $($xs:expr),* ) => {{
        print!("{} ", $x);
        W!($($xs),*);
    }}
}

#[allow(unused_macros)]
macro_rules! join {
    ($x:expr, $($xs:expr),*; $sep:expr) => { concat!($x, $($sep, $xs),*) }
}

#[allow(unused_macros)]
macro_rules! dump {
    ($($x:expr),*) => {
        eprintln!(join!($(concat!(stringify!($x), " = {:?}")),*; ", "), $($x),*);
    }
}

// }}}

fn main() {
    let s = gets();
    let lower = s.chars().filter(|c| c.is_lowercase()).count();
    let upper = s.chars().filter(|c| c.is_uppercase()).count();
    if lower >= upper {
        println!("{}", s.to_lowercase());
    } else {
        println!("{}", s.to_uppercase());
    }
}


use std::io;

fn main() {
    let (simple,word)=input();
    let mut upper=0;
    let mut lower=0;
    for i in word{
        if i.is_uppercase(){
            upper+=1;
            continue;
        }
        lower+=1;
    }
    if upper>lower{
        println!("{}",simple.to_uppercase());
    }else{
        println!("{}",simple.to_lowercase());
    }
}
fn read() -> String{
    let mut input=String::new();
    io::stdin().read_line(&mut input).expect("unable to read");
    input.trim().to_string()
}

fn input() -> (String,Vec<char>){
    let inp=read();
    let l:Vec<char>=inp.chars().collect();
    (inp,l)
}
/*  let n=read().parse::<i32>().expect("Failed to parse");
    let inp=read();
    (n,inp.split_whitespace().map(|x| x.parse::<i32>().expect("Failed to parse")).collect())
    let list: Vec<_>=inp.split_whitespace().collect();
    let qu: Vec<_>=read().chars().collect();
    (list[0].parse::<i32>().expect("Failed to parse"),
    list[1].parse::<i32>().expect("Failed to parse"),qu)
*/


//! http://codeforces.com/contest/59/problem/A

fn main() {
  use std::io;
  let mut buf = String::new();
  io::stdin().read_line(&mut buf).unwrap();
  let str = buf.trim();
  let mut count = 0i32;
  for c in str.chars() {
    if c.is_uppercase() {
      count += 1;
    } else if c.is_lowercase() {
      count -= 1;
    }
  }
  println!("{}",
    if count > 0 {
      str.to_uppercase()
    } else {
      str.to_lowercase()
    }
  );
}


use std::io;
use std::io::prelude::*;

fn main() {
    let stdin = io::stdin();
    let mut s="".to_string();
    let mut iter = stdin.lock().lines();
    s=iter.next().unwrap().unwrap();

    let mut up=0;
    let mut down=0;
    for i in s.chars() {
    	if i.is_uppercase() {
    		up+=1;
    	}
    	else{
    		down+=1;
    	}
    }
    if down>=up {
    	println!("{}",s.to_lowercase());
    }
    else{
    	println!("{}",s.to_uppercase());
    }
}


use std::io::stdin;

fn main() {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    let (mut l, mut h) = (0, 0);
    for i in buf.trim_end().as_bytes() {
        if *i >= 65 && *i <= 91 {
            h += 1;
        } else {
            l += 1;
        }
    }
    if l < h {
        println!("{}", buf.to_uppercase());
    } else {
        println!("{}", buf.to_lowercase());
    }
}


use std::io;

#[allow(unused_macros)]
macro_rules! read {
    ($out:ident as $type:ty) => {
        let mut inner = String::new();
        io::stdin().read_line(&mut inner).expect("A String");
        let $out = inner.trim().parse::<$type>().expect("Parseble");
    };
}

#[allow(unused_macros)]
macro_rules! read_str {
    ($out:ident) => {
        let mut inner = String::new();
        io::stdin().read_line(&mut inner).expect("A String");
        let $out = inner.trim();
    };
}

#[allow(unused_macros)]
macro_rules! read_vec {
    ($out:ident as $type:ty) => {
        let mut inner = String::new();
        io::stdin().read_line(&mut inner).unwrap();
        let $out = inner
            .trim()
            .split_whitespace()
            .map(|s| s.parse::<$type>().unwrap())
            .collect::<Vec<$type>>();
    };
}

fn main(){
    read_vec!(inp as i32);
    let mut vector = vec![inp[0], inp[1], inp[2]];
    let mut ans: i32 = 0;
    let d = inp[3];
    vector.sort();

    let a = vector[0];
    let b = vector[1];
    let c = vector[2];

    ans += if b-a >= d { 0 } else { d-(b-a) };
    ans += if c-b >= d { 0 } else { d-(c-b) };

    println!("{}",ans);

}


#[allow(unused_imports)]
use std::io::{BufReader, BufWriter, stdin, stdout, Write};
use std::cmp::{min, max};
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet, BinaryHeap};

fn main() {
	let mut inp = my_input::default();
	let out = &mut BufWriter::new(stdout());
	let A:i64 = inp.scan::<i64>();
	let B:i64 = inp.scan::<i64>();
	let C:i64 = inp.scan::<i64>();
	let D:i64 = inp.scan::<i64>();
	let mut v = vec![A, B, C];
	v.sort();
	writeln!(out, "{}", max(0, D - (v[1] - v[0])) + max(0, D - (v[2] - v[1])));
}

#[derive(Default)]
struct my_input {
	buffer: Vec<String>
}

impl my_input {
	fn scan<T: std::str::FromStr>(&mut self) -> T {
		loop {
			if let Some(token) = self.buffer.pop() {
				return token.parse().ok().expect("Parsing Error");
			}
			let mut s = String::new();
			stdin().read_line(&mut s).expect("Reading Error");
			self.buffer = s.split_whitespace().rev().map(String::from).collect();
		}
	}
}


use std::cmp::{min, max};
use std::io::{self, Write};
use std::str;

struct Scanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: str::SplitAsciiWhitespace<'static>
}

#[allow(dead_code)]
impl<R: io::BufRead> Scanner<R> {
    fn new(reader: R) -> Self {
        Self { reader, buf_str: Vec::new(), buf_iter: "".split_ascii_whitespace() }
    }
    fn next<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader.read_until(b'\n', &mut self.buf_str).expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_ascii_whitespace())
            }
        }
    }

    fn next_line(&mut self) -> String {
        let mut line = String::new();
        self.reader.read_line(&mut line).expect("Failed to read line");
        line
    }

    fn next_vec<T: str::FromStr>(&mut self) -> Vec<T> {
        let mut res: Vec<T> = Vec::new();
        loop {
            loop {
                match self.buf_iter.next() {
                    Some(token) => res.push(token.parse().ok().expect("Failed parse")),
                    None => break,
                }
            }
            if res.len() > 0 {
                return res;
            }
            self.buf_str.clear();
            self.reader.read_until(b'\n', &mut self.buf_str).expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_ascii_whitespace())
            }
        }
    }
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut cin = Scanner::new(stdin.lock());
    let mut cout = io::BufWriter::new(stdout.lock());

    let mut u = vec![cin.next::<i64>(), cin.next::<i64>(), cin.next::<i64>()];
    let d = cin.next::<i64>();

    u.sort();

    writeln!(cout, "{}", max(0, d + (u[0] - u[1])) + max(0, d + (u[1] - u[2]))).ok();
}


#![allow(unused_imports)]
#![allow(dead_code)]

use std::thread;
use std::io::{ self, Read };
use std::fmt;
use std::iter::Iterator;
use std::cmp::*;
use std::collections::*;
use std::str::*;
use std::mem::*;
use std::cell::*;

struct Input {
    stdin: io::Stdin,
    buf: VecDeque<String>
}

impl Input {
    fn new() -> Input {
        Input {
            stdin: io::stdin(),
            buf: VecDeque::new()
        }
    }

    fn read<T: FromStr>(&mut self) -> T
    where <T as FromStr>::Err: fmt::Debug {
        self.next().unwrap().parse::<T>().unwrap()
    }

    fn read_2<T: FromStr, U: FromStr>(&mut self) -> (T, U)
    where <T as FromStr>::Err: fmt::Debug,
          <U as FromStr>::Err: fmt::Debug {
        (self.read(), self.read())
    }

    fn read_3<T: FromStr, U: FromStr, V: FromStr>(&mut self) -> (T, U, V)
    where <T as FromStr>::Err: fmt::Debug,
          <U as FromStr>::Err: fmt::Debug,
          <V as FromStr>::Err: fmt::Debug {
        (self.read(), self.read(), self.read())
    }

    fn read_bytes(&mut self) -> Vec<u8> {
        self.next().unwrap().into_bytes()
    }

    fn read_n<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where <T as FromStr>::Err: fmt::Debug {
        let mut v = Vec::new();
        for _ in 0..n { v.push(self.read::<T>()); }
        v
    }
}

impl Iterator for Input {
    type Item = String;
    fn next(&mut self) -> Option<String> {
        while self.buf.is_empty() {
            let mut s = String::new();
            let _res = self.stdin.read_line(&mut s);
            self.buf.extend(s.split_whitespace().map(|s| s.to_owned()));
        }
        self.buf.pop_front()
    }
}

fn run() {
    let mut ip = Input::new();
    let mut a: Vec<i64> = ip.read_n(3);
    let d: i64 = ip.read();
    a.sort();
    println!("{}", max(0, d - (a[2] - a[1])) + max(0, d - (a[1] - a[0])));
}

fn main() {
    let _ = thread::Builder::new()
        .stack_size(50 * 1024 * 1024)
        .spawn(run).unwrap()
        .join();
}


fn count(n: u32) -> u32 {
    if n == 1 {
        return 1;
    }

    if n % 2 == 1 {
        1 + count(n / 2)
    } else {
        count(n / 2)
    }
}

fn main() {
    let n = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim().parse().unwrap()
    };

    println!("{}", count(n));
}


use std::io;

fn read_line() -> (i32) {
    let mut input = String::new();

    io::stdin().read_line(&mut input).unwrap();

    let n: i32 = input.trim().parse().unwrap();

    n
}

fn main(){

    let mut n  = read_line();
    let mut bacterias = 0;

    while n > 0 {
        bacterias += n % 2;
        n = n /2;
    }

    println!("{}", bacterias);
}


#[allow(unused_imports)]
use std::cmp::{max,min};

macro_rules! readln {
    () => {{
        use std::io;

        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.trim().to_string()
    }};
    ( $t:ty ) => {{
        let input = readln!();
        input.parse::<$t>().unwrap()
    }};
    ( $( $t:ty ),+ ) => {{
        let input = readln!();
        let mut input = input.split_whitespace();
        (
            $(
                input.next().unwrap().parse::<$t>().unwrap(),
            )+
        )
    }}
}

macro_rules! readvec {
    ( $t:ty ) => {{
        let input = readln!();
        let mut input = input.split_whitespace();
        let mut result = Vec::new();
        for elem in input {
            result.push(elem.parse::<$t>().unwrap());
        }
        result
    }}
}

fn solve(x:i32) -> i32 {
    if x==0 {
        return 0;
    } else if (x%2) == 0 {
        return solve(x/2);
    } else if (x%2) == 1 {
        return 1+solve(x/2);
    }
    return -1;
}

fn main() {
    let n = readln!(i32);
    println!("{}",solve(n));
}


// {{{ by shik

use std::io;

#[allow(dead_code)]
fn gets() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(unused_macros)]
macro_rules! R {
    ( $ty:ty, ... ) => {
        gets().split_whitespace().map(|x| x.parse::<$ty>().unwrap()).collect::<Vec<_>>()
    };
    ( $($ty:ty),* ) => {{
        let line = gets();
        let mut it = line.split_whitespace();
        ( $(it.next().unwrap().parse::<$ty>().unwrap(),)* )
    }}
}

#[allow(unused_macros)]
macro_rules! W {
    ( $x:expr ) => {{
        println!("{}", $x);
    }};
    ( $x:expr, $($xs:expr),* ) => {{
        print!("{} ", $x);
        W!($($xs),*);
    }}
}

#[allow(unused_macros)]
macro_rules! join {
    ($x:expr, $($xs:expr),*; $sep:expr) => { concat!($x, $($sep, $xs),*) }
}

#[allow(unused_macros)]
macro_rules! dump {
    ($($x:expr),*) => {
        eprintln!(join!($(concat!(stringify!($x), " = {:?}")),*; ", "), $($x),*);
    }
}

// }}}

fn main() {
    let (x, ) = R!(usize);
    let mut ans = 0;
    for i in 0.. {
        if (x >> i) == 0 {
            break;
        }
        ans += (x >> i) % 2;
    }
    println!("{}", ans);
}


//spnauti-rust
#[allow(unused_macros)]
macro_rules! a {
    ($c: tt, $x: expr, $y: expr) => {{
        let b = $y; let a = &mut $x;
        if b $c *a { *a = b; true } else { false }
    }};
}
struct WordReader {
    it : std::vec::IntoIter<String>,
}
#[allow(dead_code)]
impl WordReader {
    fn new<T: std::io::Read>(mut reader: T) -> WordReader {
        let mut s = String::new();
        reader.read_to_string(&mut s).unwrap();
        WordReader {
            it : s.split_ascii_whitespace().map(String::from)
            .collect::<Vec<_>>().into_iter()
        }
    }
    fn from_stdin() -> WordReader {
        WordReader::new(std::io::stdin())
    }
    fn s(&mut self) -> String {
        self.it.next().unwrap()
    }
    fn ab(&mut self) -> Vec<u8> {
        self.it.next().unwrap().into_bytes()
    }
    fn i(&mut self) -> i32 {
        self.it.next().unwrap().parse().unwrap()
    }
    fn ai(&mut self, n: usize) -> Vec<i32> {
        let mut a = Vec::with_capacity(n);
        for _ in 0..n { a.push(self.i()); }
        a
    }
}

fn main() {
    let mut input = WordReader::from_stdin();
    let mut n = input.i();
    let mut sol = 0;
    while n > 0 {
        sol += 1;
        n -= n & -n;
    }
    println!("{}", sol);
}


use std::io;
fn main(){
    let mut s:String=String::new();
    io::stdin().read_line(&mut s).unwrap();
    let mut a:i64=s.trim().parse::<i64>().unwrap();
    let mut sum:i64=0;
    while a!=0{
        sum+=a%2;
        a/=2;
    }
    println!("{}",sum);
}


struct Scan {
    buffer: std::collections::VecDeque<String>
}

impl Scan {
    fn new() -> Scan {
        Scan { buffer: std::collections::VecDeque::new() }
    }

    fn next<T: std::str::FromStr>(&mut self)-> T {
        loop {
            if let Some(token) = self.buffer.pop_front() {
                break token.parse::<T>().ok().unwrap();
            }
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).expect("Fail to read");
            self.buffer = line.split_whitespace().map(String::from).collect();
        }
    }

}

fn _main() {
    let mut scan = Scan::new();
    let mut n: usize = scan.next();
    let mut x: usize = 0;
    while n>0 {
        if n&1 == 1 {
            x += 1;
        }
        n >>= 1;
    }
    println!("{}", x);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();
}


// https://codeforces.com/problemset/problem/579/A
use std::io;

fn main() {
    let mut n = String::new();

    io::stdin()
        .read_line(&mut n)
        .unwrap();

    let n: i64 = n.trim().parse().unwrap();

    let mut ans = 0;

    for bit in 0..64 {
        if (n & (1<<bit)) > 0 {
            ans += 1;
        }
    }

    println!("{}", ans);
}


use std::io;

macro_rules! readln {
    () => {{
        use std::io;
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.trim().to_string()
    }};
    ( $t:ty ) => {{
        let input = readln!();
        input.parse::<$t>().unwrap()
    }};
    ( $( $t:ty ),+ ) => {{
        let input = readln!();
        let mut input = input.split_whitespace();
        (
            $(
                input.next().unwrap().parse::<$t>().unwrap(),
            )+
        )
    }}
}

fn main() {
    let (result, divider) = readln!(i32, i32);

    let mut min = std::i32::MAX;
    for right in 1..divider {
        if result % right == 0 {
            let x = right + divider * result / right;
            if x < min {
                min = x;
            }
        }
    }

    println!("{}", min);
}


use std::io;

fn main() {
    let mut buffer = String::new();
    io::stdin().read_line(&mut buffer).expect("failed to read input");
    let mut buffer_iter = buffer.split_whitespace().map(|n| n.parse::<u32>().unwrap());
    let n = buffer_iter.next().unwrap();
    let k = buffer_iter.next().unwrap();

    let md = (1..k).rev().find(|x| n % x == 0).unwrap();
    println!("{}", (n / md) * k + md);
}


#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        a: chars,
        b: chars,
    }
    let pc = |a: &[char]| {
        10 * (a[0] as u8 as i32) + a[1] as u8 as i32 - 48 * 11
    };
    let p = |a: Vec<char>| {
        60 * pc(&a[0..2]) + pc(&a[3..5])
    };
    let mid = (p(a) + p(b)) / 2;
    puts!("{:02}:{:02}\n", mid / 60, mid % 60);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


use std::io::{self, BufRead};

fn parse(s: &str) -> u32 {
    s.parse().unwrap()
}

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let start_raw = lines.next().unwrap().unwrap();
    let end_raw = lines.next().unwrap().unwrap();
    let start: Vec<_> = start_raw.split(':').map(parse).collect();
    let end: Vec<_> = end_raw.split(':').map(parse).collect();

    let mut duration = 0;
    duration = duration + end[1] - start[1];
    duration += 60 * (end[0] - start[0]);

    let half = duration / 2;
    let mut half_min = start[1] + half;
    let half_hour = start[0] + (half_min / 60);
    half_min %= 60;

    println!("{:02}:{:02}", half_hour, half_min);
}


#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::prelude::BufRead;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufReader, BufWriter, Write};
#[allow(unused_imports)]
use std::mem::swap;
#[allow(unused_imports)]
use std::str::FromStr;

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let start;
    let end;
    {
        let line = buf.trim().split(":").collect::<Vec<_>>();
        start = line[0].parse::<usize>().unwrap() * 60 + line[1].parse::<usize>().unwrap();
    }
    buf.clear();
    stdin().read_line(&mut buf).unwrap();
    {
        let line = buf.trim().split(":").collect::<Vec<_>>();
        end = line[0].parse::<usize>().unwrap() * 60 + line[1].parse::<usize>().unwrap();
    }
    let mid = (start + end) / 2;
    let (h, m) = (mid / 60, mid % 60);
    if h < 10 {
        print!("0{}:", h);
    } else {
        print!("{}:", h);
    }
    if m < 10 {
        println!("0{}", m);
    } else {
        println!("{}", m);
    }
}

#[allow(dead_code)]
fn read<T>() -> T
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    return buf.trim().parse().unwrap();
}

#[allow(dead_code)]
fn read_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::with_capacity(100);
    stdin().read_line(&mut buf).unwrap();
    return buf.split_whitespace().map(|s| s.parse().unwrap()).collect();
}

#[allow(dead_code)]
fn read_matrix<T>() -> Vec<Vec<T>>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    use std::io::prelude::*;
    let stdin = stdin();
    let mut reader = BufReader::with_capacity(100 * 1024, stdin);
    let mut line = String::with_capacity(100);
    let mut matrix: Vec<Vec<T>> = Vec::new();

    while reader.read_line(&mut line).unwrap() > 0 {
        matrix.push(
            line.trim()
                .split_whitespace()
                .map(|s| s.parse().unwrap())
                .collect(),
        );
        line.clear();
    }

    return matrix;
}

#[allow(dead_code)]
fn read_chars() -> Vec<char> {
    let stdin = stdin();
    let mut buf = String::new();
    let _bytes = stdin.read_line(&mut buf).unwrap();
    return buf.trim().chars().collect();
}


//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

#[allow(unused_imports)]
use input::*;

fn main() {
    let start_time_str = input_line_str();
    let end_time_str = input_line_str();
    let start_time = start_time_str
        .split(':')
        .map(|a| a.parse::<usize>().unwrap())
        .collect::<Vec<_>>();
    let end_time = end_time_str
        .split(':')
        .map(|a| a.parse::<usize>().unwrap())
        .collect::<Vec<_>>();
    let ans = (end_time[0] * 60 + end_time[1] + start_time[0] * 60 + start_time[1]) >> 1;
    dbg!(start_time, end_time, ans);
    println!("{:02}:{:02}", ans / 60, ans % 60);
}


use std::io::{stdin, BufRead, Stdin, StdinLock};

fn get_average_time(time1: (usize, usize), time2: (usize, usize)) -> (usize, usize) {
    let time1_minutes: usize = time1.0 * 60 + time1.1;
    let time2_minutes: usize = time2.0 * 60 + time2.1;

    let time3_minutes = (time1_minutes + time2_minutes) / 2;

    return ((time3_minutes / 60), (time3_minutes % 60));
}

#[cfg(test)]
mod test {
    use super::get_average_time;

    #[test]
    fn test1() {
        let time1: (usize, usize) = (10, 0);
        let time2: (usize, usize) = (11, 0);
        let time_result: (usize, usize) = get_average_time(time1, time2);

        assert_eq!(time_result, (10, 30));
    }
    #[test]
    fn test2() {
        let time1: (usize, usize) = (11, 10);
        let time2: (usize, usize) = (11, 12);
        let time_result: (usize, usize) = get_average_time(time1, time2);

        assert_eq!(time_result, (11, 11));
    }
    #[test]
    fn test3() {
        let time1: (usize, usize) = (1, 2);
        let time2: (usize, usize) = (3, 2);
        let time_result: (usize, usize) = get_average_time(time1, time2);

        assert_eq!(time_result, (2, 2));
    }
}

fn read_data() -> ((usize, usize), (usize, usize)) {
    let stdin_stream: Stdin = stdin();
    let mut stdin_handle: StdinLock = stdin_stream.lock();

    let mut str1: String = String::new();
    stdin_handle.read_line(&mut str1).unwrap();
    let str1_tokens: Vec<usize> = str1
        .trim()
        .split(":")
        .map(|s| s.parse::<usize>().unwrap())
        .collect();

    let mut str2: String = String::new();
    stdin_handle.read_line(&mut str2).unwrap();
    let str2_tokens: Vec<usize> = str2
        .trim()
        .split(":")
        .map(|s| s.parse::<usize>().unwrap())
        .collect();

    return (
        (str1_tokens[0], str1_tokens[1]),
        (str2_tokens[0], str2_tokens[1]),
    );
}

fn main() {
    let (time1, time2): ((usize, usize), (usize, usize)) = read_data();

    let time_result: (usize, usize) = get_average_time(time1, time2);

    println!("{:02}:{:02}", time_result.0, time_result.1);
}


use std::io;

fn main() {
    let mut string = String::new();
    io::stdin().read_line(&mut string)
        .expect("Read error!");

    let int_vec: Vec<_> = string.trim().split(' ')
        .map(|x| x.parse::<u64>().expect("Not an integer!"))
        .collect();

    if int_vec.len() != 3 {
        panic!("Bad input");
    }

    println!("{}", ((int_vec[0] as f64) / (int_vec[2] as f64)).ceil() *
                    ((int_vec[1] as f64) / (int_vec[2] as f64)).ceil() );
}


fn main() {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    let mut v: Vec<u128> = Vec::with_capacity(3);
    for i in input.split_whitespace() {
    v.push(i.trim().parse().unwrap());
    }
    let (mut k,mut l) = (v[0]/v[2] , v[1]/v[2] );
    if v[0]%v[2] != 0 { k+=1}
    if v[1]%v[2] != 0 { l+=1}
    println!("{}",k*l);
}


use std::io::stdin;

//[TIME TO INIT: 10:38]

fn main() {

    let mut contents = String::new();
    let mut vec = vec![];

    stdin().read_line(&mut contents).unwrap();

    vec = contents
        .split(" ")
        .map(|x| x.trim().parse::<i64>().unwrap())
        .collect();

    let mut width = vec[0] / vec[2];
    let mut height = vec[1] / vec[2];

    if vec[0] % vec[2] != 0 {
        width += 1;
    }
    if vec[1] % vec[2] != 0 {
        height += 1;
    }
    println!("{}", width * height);

}


fn main() {
    // The input n, m, a
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();

    // Caculate the results
    let v: Vec<f64> = s.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let r = ((v[0] / v[2]).ceil() * (v[1] / v[2]).ceil()).floor();

    // Display the results
    println!("{}", r);
}


use std::io;
fn main(){
    let mut s:String=String::new();
    io::stdin().read_line(&mut s).unwrap();
    let mut a:Vec<i64>=Vec::new();
    let mut c:usize=0;
    let mut n:usize=0;
    while c<=s.len()-1{
        n=c;
        if s.chars().nth(c).unwrap()!=' '{
            while s.chars().nth(n).unwrap()!=' ' && n<s.len()-1{
                n+=1;
            }
            a.push(s[c..n+1].trim().to_string().parse().unwrap());
            c=n;
        }
        c+=1;
    }
    let m:i64=if a[0]%a[2]>0{a[0]/a[2]+1}else{a[0]/a[2]};
    let n:i64=if a[1]%a[2]>0{a[1]/a[2]+1}else{a[1]/a[2]};
    println!("{}",m*n);
}


use std::io;

#[allow(unused_macros)]
macro_rules! read {
    ($out:ident as $type:ty) => {
        let mut inner = String::new();
        io::stdin().read_line(&mut inner).expect("A String");
        let $out = inner.trim().parse::<$type>().expect("Parseble");
    };
}

#[allow(unused_macros)]
macro_rules! read_str {
    ($out:ident) => {
        let mut inner = String::new();
        io::stdin().read_line(&mut inner).expect("A String");
        let $out = inner.trim();
    };
}

#[allow(unused_macros)]
macro_rules! read_vec {
    ($out:ident as $type:ty) => {
        let mut inner = String::new();
        io::stdin().read_line(&mut inner).unwrap();
        let $out = inner
            .trim()
            .split_whitespace()
            .map(|s| s.parse::<$type>().unwrap())
            .collect::<Vec<$type>>();
    };
}

fn main() {
    read_vec!(inp as u64);
    let a = (inp[0] as f64 / inp[2] as f64).ceil() as u64;
    let b = (inp[1] as f64 / inp[2] as f64).ceil() as u64;

    println!("{}", a * b);
}


fn readln() -> String {
    let stdin = std::io::stdin();
    let mut line = String::new();
    stdin.read_line(&mut line).unwrap();
    String::from(line.trim())
}

macro_rules! scanln {
    ($($ty: ty),*) => {{
        let line = readln();
        let mut iter = line.split_whitespace();
        ($(iter.next().unwrap().parse::<$ty>().unwrap()),*)
    }}
}

fn ceil(a: i32, b: i32) -> u64 {
    (a as u64 - 1) / b as u64  + 1
}

fn main() {
    let (n, m, a) = scanln!(i32, i32, i32);
    println!("{}", ceil(n, a) * ceil(m, a));
}


use std::io;

fn main() {
    let mut a_str = String::new();
    io::stdin().read_line(&mut a_str).expect("read error");
    let vec = a_str.split_whitespace()
        .map(|x| x.parse::<u64>().expect("parse error"))
        .collect::<Vec<u64>>();

    let m = vec[0];
    let n = vec[1];
    let a = vec[2];

    let x: u64;
    if m % a != 0 {
        x = (m / a) + 1;
    } else {
        x = m / a;
    }

    let y: u64;
    if n % a != 0 {
        y = (n / a) + 1;
    } else {
        y = n / a;
    }

    println!("{}", x*y);
}


fn main() {
    let mut sc = new(std::io::stdin());
    let k = sc.next();
    let mut rm = 0;
    for _ in 0..k {
        let r = sc.next();
        if r > rm {
            rm = r;
        }
    }
    let mut res = rm - 25;
    if res < 0 {
        res = 0;
    }
    println!("{}", res);
}

use std::io;
use std::io::BufRead;

pub struct Scanner<R: io::Read> {
    br: io::BufReader<R>,
    // Read tokens are stored in reversed order per line.
    buf: Vec<String>,
}

pub fn new<R: io::Read>(r: R) -> Scanner<R> {
    Scanner::new(r)
}

impl<R: io::Read> Scanner<R> {
    #[inline]
    fn new(r: R) -> Scanner<R> {
        Scanner {
            br: io::BufReader::new(r),
            buf: vec![],
        }
    }
    #[inline]
    pub fn next<T>(&mut self) -> T
        where T: std::str::FromStr,
              T::Err: std::fmt::Debug
    {
        self.next_string().map(|s| s.parse::<T>().expect("Parse failed: ")).unwrap()
    }
    fn next_string(&mut self) -> Option<String> {
        self.buf.pop().or_else(|| match self.update() {
            true => self.next_string(),
            false => None,
        })
    }
    #[inline]
    fn update(&mut self) -> bool {
        let mut s = String::new();
        let res = self.br.read_line(&mut s);
        match res.expect("I/O error.") {
            0 => false,
            _ => {
                self.buf = s.split_whitespace().map(|x| x.to_string()).rev().collect();
                true
            }
        }
    }
}


#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(overflowing_literals)]
#![allow(unused_must_use)]

use std::collections::*;
use std::io::*;
use std::cmp::{min, max};
use std::f64::consts::*;
use std::mem::swap;
use std::fs::File;
use std::rc::*;
use std::ascii::*;
use std::ops::*;

const INF: i32 = std::i32::MAX;
const LINF: i64 = std::i64::MAX;
const MOD: i32 = 1000000007;

#[derive(PartialEq, PartialOrd, Eq, Ord, Copy, Clone)]
struct Pair<A: Eq + Ord + Clone, B: Eq + Ord + Clone>(A, B);

struct Input<Buf: BufRead>
{
	buffer: Buf
}

impl<Buf: BufRead> Input<Buf>
{
	fn read_line(&mut self) -> String {
		let mut v = Vec::new();
		let mut x = [255u8];
		self.buffer.read(&mut x).expect("EOF");
		while x[0] < b' ' && x[0] != 255u8 {
			x[0] = 255u8;
			self.buffer.read(&mut x).expect("EOF");
		}
		while x[0] >= b' ' && x[0] != 255u8 {
			v.push(x[0]);
			x[0] = 255u8;
			self.buffer.read(&mut x).expect("EOF");
		}
		String::from_utf8(v).unwrap()
	}

	fn read_word(&mut self) -> String {
		let mut v = Vec::new();
		let mut x = [255u8];
		self.buffer.read(&mut x).expect("EOF");
		while x[0] <= b' ' && x[0] != 255u8 {
			x[0] = 255u8;
			self.buffer.read(&mut x).expect("EOF");
		}
		while x[0] > b' ' && x[0] != 255u8 {
			v.push(x[0]);
			x[0] = 255u8;
			self.buffer.read(&mut x).expect("EOF");
		}
		String::from_utf8(v).unwrap()
	}
	#[inline]
	fn read_int(&mut self) -> i32 {
		self.read_word().parse::<i32>().expect("Parsing error")
	}
	#[inline]
	fn read_long(&mut self) -> i64 {
		self.read_word().parse::<i64>().expect("Parsing error")
	}
	#[inline]
	fn read_usize(&mut self) -> usize {
		self.read_word().parse::<usize>().expect("Parsing error")
	}
	#[inline]
	fn read_double(&mut self) -> f64 {
		self.read_word().parse::<f64>().expect("Parsing error")
	}
}
macro_rules! read {
    () => {};
	($inf:ident,$($t:ty),*) => ({($({$inf.read_word().parse::<$t>().expect("Parsing error")}),*)});
}
fn gcd<T: RemAssign + Ord + From<i32> + Copy>(x: T, y: T) -> T {
	let (mut a, mut b) = (x, y);
	while b > T::from(0) {
		a %= b;
		swap(&mut a, &mut b);
	}
	a
}

fn main() {
	match std::env::var("home") {
		Ok(_x) => {
			let mut inf = Input {
				buffer: BufReader::new(File::open("input.txt").expect("File not found"))
			};
			let mut ouf = BufWriter::new(stdout());
			solve(&mut inf, &mut ouf);
		}
		Err(_e) => {
			let mut inf = Input { buffer: BufReader::new(stdin()) };
			let mut ouf = BufWriter::new(stdout());
			solve(&mut inf, &mut ouf);
		}
	}
}

fn solve<Inner: BufRead, Output: Write>(inf: &mut Input<Inner>, ouf: &mut Output)
{
	let k = read!(inf,usize);
	let mut v = vec![0; k];
	for i in 0..k {
		v[i] = read!(inf,i32);
	}
	v.sort();
	writeln!(ouf, "{}", max(v[k - 1] - 25, 0));
}


#![allow(unused_imports)]
#![allow(unused_macros)]
use std::io::{StdinLock, stdin, BufRead};
use std::collections::*;
use std::cmp::*;

fn scan_helper(lock : &mut StdinLock) -> String {
    let mut buffer = String::new();
    lock.read_line(&mut buffer).ok();
    buffer
}

macro_rules! scan {
    ($lock:ident, $t:ty) => ({
        scan_helper(&mut $lock).split_whitespace()
            .next().unwrap()
            .parse::<$t>().unwrap()
    });
    ($lock:ident, $($t:ty),+) => ({
        let buffer = scan_helper(&mut $lock);
        let mut iter = buffer.split_whitespace();
        ($(
            {
                iter.next().unwrap()
                    .parse::<$t>().unwrap()
            },
        )+)
    })
}

macro_rules! scan_iter {
    ($lock:ident, $t:ty) => ({
        scan_helper(&mut $lock).split_whitespace()
            .map(|x| x.parse::<$t>().unwrap())
            .collect()
    })
}

trait Ext {
    fn idx(&self) -> usize;
    fn num(&self) -> i64;
}

macro_rules! ext {
    ($t:ty) => (
        impl Ext for $t {
            #[inline]
            fn idx(&self) -> usize {
                *self as usize
            }

            #[inline]
            fn num(&self) -> i64 {
                *self as i64
            }
        }
    )
}
ext!(i64);
ext!(usize);

macro_rules! derive_regular {
    ($t:ty) => (
        impl Ord for $t {
            fn cmp(&self, other : &$t) -> Ordering {
                self.partial_cmp(other).unwrap()
            }
        }
        impl PartialEq for $t {
            fn eq(&self, other : &$t) -> bool {
                self.cmp(other) == Ordering::Equal
            }
        }
        impl Eq for $t {}
    )
}

fn main() {
    let stdin = stdin();
    let mut s = stdin.lock();
    let n = scan!(s, usize);
    let data : Vec<i64> = scan_iter!(s, i64);
    let m = data.iter().max().unwrap();
    println!("{}", max(0, m - 25));
}


fn read_str() -> String {
    let mut buffer: String = String::new();
    std::io::stdin().read_line(&mut buffer).expect("Error");
    buffer.trim().to_string()
}

fn main() {
    read_str();
    let mut remove: u8 = 0;
    let stones: String = read_str();
    let mut current: char = stones.chars().nth(0).expect("Error");

    for stone in stones[1..].chars() {
        if current == stone { remove += 1; }
        current = stone;
    }
    println!("{}", remove)
}


pub fn main(){
    let chars: Vec<char> = input().chars().collect();
    let mut color = chars[0];
    let mut extras = -1;
    for c in chars {
        if c == color {
            extras += 1;
        } else {
            color = c;
        }
    }
    println!("{}", extras);
}

fn input() -> String {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input);
    input = String::new();
    std::io::stdin().read_line(&mut input);
    input
}


use std::io;
fn read() -> String{
    let mut input=String::new();
    io::stdin().read_line(&mut input).expect("unable to read");
    input.trim().to_string()
}
fn main() {
    let mut sum=0;
    let _=read().parse::<i32>().unwrap();
    let list: Vec<_>=read().chars().collect();
    let mut first=".".to_string();
    for i in &list{
        if i.to_string()==first{
            sum+=1;
        }first=i.to_string();
    }println!("{}",sum)
}


fn read() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).expect("???");
    res
}

fn parse_int(s: &str) -> usize {
    s.trim().parse().expect("???")
}

fn parse_ints(s: &str) -> Vec<usize> {
    s.split_whitespace().map(parse_int).collect()
}

fn main() {
    let n = parse_int(&read());
    let s = read().into_bytes();
    let mut curr = b' ';
    let mut res = 0;
    for c in s.into_iter() {
        if curr == c {
            res += 1;
        }
        curr = c;
    }
    println!("{}", res);
}


use std::io;

fn main() {
    let mut string = String::new();
    io::stdin().read_line(&mut string)
        .expect("Read error!");

    let count = string.trim().parse::<usize>().expect("Not an integer!");

    string.clear();
    io::stdin().read_line(&mut string)
        .expect("Read error!");

    let bytes = string.trim().as_bytes();
    let mut cnt = 0;

    for i in 1..count {
        if bytes[i - 1] == bytes[i] {
            cnt += 1;
        }
    }

    println!("{}", cnt);
}


use std::io;
use std::io::{Read, Write};

fn solve(input: &mut Read, output: &mut Write) {
    let mut sin = String::new();
    input.read_to_string(&mut sin).unwrap();
    let mut chars = sin.lines().skip(1).next().unwrap().trim().chars();
    let mut last = chars.next().unwrap();
    let res = chars.fold(0, |acc, x| {
        if x == last {
            acc + 1
        } else {
            last = x;
            acc
        }
    });

    output.write(res.to_string().trim().as_bytes()).unwrap();
}

fn main() {
    solve(&mut io::stdin(), &mut io::stdout());
}

#[cfg(test)]
mod tests {
    use std::fs::File;
    use std::io::Read;
    use solve;

    #[test]
    fn test() {
        (1..3 + 1).map(|x| {
            println!("test #{}", x);
            let mut fin = File::open("./src/in".to_string() + &x.to_string() + ".txt").unwrap();
            let mut buf: Vec<u8> = Vec::new();
            solve(&mut fin, &mut buf);
            let res = String::from_utf8(buf).unwrap();

            let mut fout = File::open("./src/out".to_string() + &x.to_string() + ".txt").unwrap();
            let mut sout = String::new();
            fout.read_to_string(&mut sout).unwrap();
            assert_eq!(res, sout.trim());

        }).count();

    }
}


use std::io::BufRead;

macro_rules! read_line(
    () => {{
        let stdin = std::io::stdin();
        let stdin = stdin.lock();
        let mut lines = stdin.lines();
        lines.next().unwrap()
    }}
);

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let amount: usize = read_line!()?.parse()?;
    let colors: String = read_line!()?.parse()?;
    let chars: Vec<_> = colors.chars().collect();
    let result = chars.windows(2).fold(0, |acc, pair| if pair[0] == pair[1] { acc + 1} else { acc });
    println!("{}", result);
    Ok(())
}


use std::io;

fn main() {
	let mut n = String::new();
	io::stdin().read_line(&mut n).unwrap();
	let mut stones = String::new();
	io::stdin().read_line(&mut stones).unwrap();

	let mut ans: i32 = 0;
	let mut prev_stone = '0';
	for stone in stones.trim().chars() {
		if stone == prev_stone {
			ans += 1;
		} else {
			prev_stone = stone;
		}
	}
	println!("{}", ans);
}


use std::io::{self, Stdin, stdin};
use std::str::FromStr;
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    let stdin = stdin();

    let cases = {
        let l = line(&stdin)?;
        let mut ite = l.trim().split(' ');
        usize::from_str(ite.next().unwrap())?
    };

    for _ in 0..cases {
        let it = {
            let l = line(&stdin)?;
            let mut ite = l.trim().split(' ');
            u32::from_str(ite.next().unwrap())?
        };

        let mut best: u32 = 1;
        for d in 2..=f64::sqrt(it as f64) as u32 {
            if it % d == 0 {
                let nd = it / d;
                if nd > best {
                    best = nd;
                }
            }
        }
        println!("{} {}", best, it - best);
    }

    Ok(())
}

fn line(s: &Stdin) -> io::Result<String> {
    let mut i = String::new();
    s.read_line(&mut i)?;
    Ok(i)
}


#![allow(dead_code)]
#![allow(unused_imports)]

use std::cmp::*;
use std::collections::*;
use std::io;
use std::ops;
use std::str::FromStr;

#[derive(Clone, Debug, Default)]
struct ProblemState {
}

fn gcd(a: u128, b: u128) -> u128 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

impl Problem {
    fn solve(&mut self) {
        let n: u64 = self.scan();

        let mut x = 2;
        let mut k = 1;

        while x * x <= n {
            if n % x == 0 {
                k = n / x;
                break;
            }

            x += 1;
        }

        println!("{} {}", k, n - k);
    }
}

fn main() {
    Problem::new().solve_cases();
}

struct Problem {
    input_state: InputState,
    problem_state: ProblemState,
}

struct InputState {
    stdin: io::Stdin,
    buffer: String,
    tokens: VecDeque<String>,
}

impl Problem {
    fn new() -> Self {
        Self {
            input_state: InputState {
                stdin: io::stdin(),
                buffer: String::new(),
                tokens: VecDeque::new(),
            },
            problem_state: Default::default(),
        }
    }

    fn solve_cases(&mut self) {
        for _ in 0usize..self.scan() {
            self.solve()
        }
    }

    fn scan<T: FromStr>(&mut self) -> T {
        while self.input_state.tokens.is_empty() {
            self.input_state.stdin.read_line(&mut self.input_state.buffer).unwrap();

            for token in self.input_state.buffer.split_ascii_whitespace() {
                self.input_state.tokens.push_back(token.to_string());
            }

            self.input_state.buffer.clear();
        }

        self.input_state.tokens.pop_front().unwrap().parse().ok().unwrap()
    }

    fn scan_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).into_iter().map(|_| self.scan()).collect()
    }

    fn scan_line(&mut self) -> String {
        let mut line = String::new();
        self.input_state.stdin.read_line(&mut line).unwrap();
        while line.ends_with('\n') || line.ends_with('\r') { line.pop(); }
        line
    }

    fn scan_line_vec(&mut self, n: usize) -> Vec<String> {
        (0..n).into_iter().map(|_| self.scan_line()).collect()
    }
}

impl ops::Deref for Problem {
    type Target = ProblemState;

    fn deref(&self) -> &ProblemState {
        &self.problem_state
    }
}

impl ops::DerefMut for Problem {
    fn deref_mut(&mut self) -> &mut ProblemState {
        &mut self.problem_state
    }
}


/*
    date   : 2020 / 5 / 5
    author : quickn (quickn.ga)
    email  : quickwshell@gmail.com
*/

use std::io::{self, BufWriter, Write};

mod scanner {
    use std::{io, str};
    /* https://github.com/EbTech/rust-algorithms */

    /// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts
    /// **REQUIRES** Rust 1.34 or higher
    pub struct UnsafeScanner<R> {
        reader: R,
        buf_str: Vec<u8>,
        buf_iter: str::SplitAsciiWhitespace<'static>,
    }

    impl<R: io::BufRead> UnsafeScanner<R> {
        pub fn new(reader: R) -> Self {
            Self {
                reader,
                buf_str: Vec::new(),
                buf_iter: "".split_ascii_whitespace(),
            }
        }

        /// This function should be marked unsafe, but noone has time for that in a
        /// programming contest. Use at your own risk!
        pub fn token<T: str::FromStr>(&mut self) -> T {
            loop {
                if let Some(token) = self.buf_iter.next() {
                    return token.parse().ok().expect("Failed parse");
                }
                self.buf_str.clear();
                self.reader
                    .read_until(b'\n', &mut self.buf_str)
                    .expect("Failed read");
                self.buf_iter = unsafe {
                    let slice = str::from_utf8_unchecked(&self.buf_str);
                    std::mem::transmute(slice.split_ascii_whitespace())
                }
            }
        }
    }
}

use std::cmp::{max, min};
use std::mem::swap;

fn gcd(a: usize, b: usize) -> usize {
    let (mut a_t, mut b_t) = (max(a, b), min(a, b));
    while b_t != 0 {
        a_t %= b_t;
        swap(&mut a_t, &mut b_t);
    }
    a_t
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let (mut scan, mut sout) = (
        scanner::UnsafeScanner::new(stdin.lock()),
        BufWriter::new(stdout.lock()),
    );
    let t: usize = scan.token();
    for i in 0..t {
        let n: usize = scan.token();
        let mut func = n;
        let mut a_t = n;
        for a in 1..=((n as f64).sqrt() as usize) {
            if n % a == 0 {
                if (n/a)*(a-1) < func && a != 1 {
                    a_t = n / a;
                    func = (n/a)*(a-1);
                }
                if a*((n / a)-1) < func && (n / a) != 1 {
                    a_t = a;
                    func = a*((n / a)-1);
                }
            }
        }
        writeln!(sout, "{} {}", a_t, n-a_t).ok();
    }
}


#![allow(unused_imports)]
#![allow(dead_code)]

use std::io::Read;

struct State {
    n: usize,
}

fn solve(st: &mut State) {
    let n = st.n;
    let mut i = 2;
    while i * i <= n {
        if n % i == 0 {
            print!("{} {}\n", n/i, n/i * (i-1));
            return;
        }
        i += 1;
    }
    print!("{} {}\n", 1, n-1);
}
fn main() {
    let mut buffer = String::new();
    std::io::stdin().read_to_string(&mut buffer).unwrap();
    let mut input = buffer.split_whitespace();

    let t: usize = input.next().unwrap().parse().unwrap();
    for _ in 0..t {
        let n: usize = input.next().unwrap().parse().unwrap();
        //let a: Vec<usize> = (0..n).map(|_| input.next().unwrap().parse().unwrap()).collect();
        solve(&mut State{n: n});
    }

}


#![allow(unused_imports, unused_macros)]

use kyoproio::*;
use std::{
    collections::*,
    io::{self, prelude::*},
    iter,
    mem::{replace, swap},
};

fn main() -> io::Result<()> {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024)
        .spawn(|| {
            let stdin = io::stdin();
            let stdout = io::stdout();
            run(KInput::new(stdin.lock()), io::BufWriter::new(stdout.lock()))
        })?
        .join()
        .unwrap();
    Ok(())
}

fn run<I: Input, O: Write>(mut kin: I, mut out: O) {
    macro_rules! output { ($($args:expr),+) => { write!(&mut out, $($args),+).unwrap(); }; }
    macro_rules! outputln {
        ($($args:expr),+) => { output!($($args),+); outputln!(); };
        () => { output!("\n"); if cfg!(debug_assertions) { out.flush().unwrap(); } }
    }

    let t: usize = kin.input();
    let ps = primes(100000);
    'test: for _ in 0..t {
        let n: usize = kin.input();
        for &p in &ps {
            if n % p == 0 {
                let x = n / p;
                outputln!("{} {}", x, x * (p - 1));
                continue 'test;
            }
        }
        outputln!("{} {}", 1, n - 1);
    }
}

pub fn primes(n: usize) -> Vec<usize> {
    // 1, 7, 11, 13, 17, 19, 23, 29
    const SKIP: [u8; 8] = [6, 4, 2, 4, 2, 4, 6, 2];
    const XTOI: [u8; 15] = [
        0, 0, 0, 1, 0, 2, 3, 0, 4, 5, 0, 6, 0, 0, 7,
    ];
    let mut sieve = vec![0u8; n / 30 + 1];
    let mut ps = vec![2, 3, 5];
    if n <= 4 {
        ps.truncate([0, 0, 1, 2, 2][n]);
        return ps;
    }
    let mut x = 7;
    let mut i = 1;
    while x <= n {
        if sieve[i / 8] & 1 << i % 8 == 0 {
            ps.push(x);
            let mut j = i;
            let mut y = x * x;
            while y <= n {
                sieve[y / 30] |= 1 << XTOI[y / 2 % 15];
                y += x * SKIP[j % 8] as usize;
                j += 1;
            }
        }
        x += SKIP[i % 8] as usize;
        i += 1;
    }
    ps
}

// -----------------------------------------------------------------------------
pub mod kyoproio {
    use std::io::prelude::*;
    pub trait Input {
        fn str(&mut self) -> &str;
        fn input<T: InputParse>(&mut self) -> T {
            T::input(self)
        }
        fn iter<T: InputParse>(&mut self) -> Iter<T, Self> {
            Iter(self, std::marker::PhantomData)
        }
        fn seq<T: InputParse, B: std::iter::FromIterator<T>>(&mut self, n: usize) -> B {
            self.iter().take(n).collect()
        }
    }
    pub struct KInput<R> {
        src: R,
        buf: String,
        pos: usize,
    }
    impl<R: BufRead> KInput<R> {
        pub fn new(src: R) -> Self {
            Self {
                src,
                buf: String::with_capacity(1024),
                pos: 0,
            }
        }
    }
    impl<R: BufRead> Input for KInput<R> {
        fn str(&mut self) -> &str {
            loop {
                if self.pos >= self.buf.len() {
                    self.pos = 0;
                    self.buf.clear();
                    if self.src.read_line(&mut self.buf).expect("io error") == 0 {
                        return &self.buf;
                    }
                }
                let range = self.pos
                    ..self.buf[self.pos..]
                        .find(|c: char| c.is_ascii_whitespace())
                        .map(|i| i + self.pos)
                        .unwrap_or_else(|| self.buf.len());
                self.pos = range.end + 1;
                if range.end > range.start {
                    return &self.buf[range];
                }
            }
        }
    }
    pub struct Iter<'a, T, I: ?Sized>(&'a mut I, std::marker::PhantomData<*const T>);
    impl<'a, T: InputParse, I: Input + ?Sized> Iterator for Iter<'a, T, I> {
        type Item = T;
        fn next(&mut self) -> Option<T> {
            Some(self.0.input())
        }
    }
    pub trait InputParse: Sized {
        fn input<I: Input + ?Sized>(src: &mut I) -> Self;
    }
    impl InputParse for Vec<u8> {
        fn input<I: Input + ?Sized>(src: &mut I) -> Self {
            src.str().as_bytes().to_owned()
        }
    }
    macro_rules! from_str_impl {
        { $($T:ty)* } => {
            $(impl InputParse for $T {
                fn input<I: Input + ?Sized>(src: &mut I) -> Self {
                    src.str().parse::<$T>().expect("parse error")
                }
            })*
        }
    }
    from_str_impl! {
        String char bool f32 f64 isize i8 i16 i32 i64 i128 usize u8 u16 u32 u64 u128
    }
    macro_rules! tuple_impl {
        ($H:ident $($T:ident)*) => {
            impl<$H: InputParse, $($T: InputParse),*> InputParse for ($H, $($T),*) {
                fn input<I: Input + ?Sized>(src: &mut I) -> Self {
                    ($H::input(src), $($T::input(src)),*)
                }
            }
            tuple_impl!($($T)*);
        };
        () => {}
    }
    tuple_impl!(A B C D E F G);
    #[macro_export]
    macro_rules! kdbg {
        ($($v:expr),*) => {
            if cfg!(debug_assertions) { dbg!($($v),*) } else { ($($v),*) }
        }
    }
}


use std::fmt::Debug;
use std::str::FromStr;

pub struct TokenReader {
    reader: std::io::Stdin,
    tokens: Vec<String>,
    index: usize,
}

impl TokenReader {
    pub fn new() -> Self {
        Self {
            reader: std::io::stdin(),
            tokens: Vec::new(),
            index: 0,
        }
    }

    pub fn next<T>(&mut self) -> T
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index += 1;
        self.tokens[self.index - 1].parse().unwrap()
    }

    pub fn vector<T>(&mut self) -> Vec<T>
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index = self.tokens.len();
        self.tokens.iter().map(|tok| tok.parse().unwrap()).collect()
    }

    pub fn load_next_line(&mut self) {
        let mut line = String::new();
        self.reader.read_line(&mut line).unwrap();

        self.tokens = line
            .split_whitespace()
            .map(String::from)
            .collect();
        self.index = 0;
    }
}

fn gcd(mut a: i64, mut b: i64) -> i64 {
    while b != 0 {
        let r = a % b;
        a = b;
        b = r;
    }
    a
}

fn lcm(a: i64, b: i64) -> i64 {
    ((a as i64 * b as i64) / (gcd(a, b) as i64)) as i64
}

fn solve(n: i64) -> (i64, i64) {
    let mut res = (n / 2, n - n / 2);
    let mut res_lcm = lcm(res.0, res.1);

    let mut i = 1i64;
    while i * i <= n as i64 {
        if n % i as i64 != 0 {
            i += 1;
            continue;
        }

        let a = i as i64;
        let b = n - a;
        let curr_lcm = lcm(a, b);

        if curr_lcm < res_lcm && a > 0 && b > 0 {
            res_lcm = curr_lcm;
            res = (a, b);
        }

        let a = n / i as i64;
        let b = n - a;
        let curr_lcm = lcm(a, b);

        if curr_lcm < res_lcm && a > 0 && b > 0 {
            res_lcm = curr_lcm;
            res = (a, b);
        }
        i += 1;
    }
    res
}

fn main() {
    let mut reader = TokenReader::new();
    let tests = reader.next();

    for _ in 0..tests {
        let n = reader.next();
        let (a, b) = solve(n);
        println!("{} {}", a, b);
    }
}


macro_rules! parse_line {
    ($t: ty) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let a_str = a_str.trim();
        a_str.parse::<$t>().expect("parse error")
    });
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let mut a_iter = a_str.split_whitespace();
        (
            $(
            a_iter.next().unwrap().parse::<$t>().expect("parse error"),
            )+
        )
    })
}

#[allow(unused_macros)]
macro_rules! parse_line_to_vec {
    ($t: ty) => {{
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        (a_str
            .split_whitespace()
            .map(|x| x.parse::<$t>().unwrap())
            .collect::<Vec<$t>>())
    }};
}

use std::io::Write;

fn solve(writer: &mut std::io::BufWriter<std::io::Stdout>) {
    let n = parse_line!(u32);
    for i in 2..n {
        if i * i > n {
            break;
        }
        if n % i == 0 {
            let a = n / i;
            let b = n - a;
            writeln!(writer, "{} {}", a, b).unwrap();
            return;
        }
    }
    writeln!(writer, "1 {}", n - 1).unwrap();
}

fn main() {
    let tests = parse_line!(usize);
    let mut writer = std::io::BufWriter::new(std::io::stdout());
    for _ in 0..tests {
        solve(&mut writer);
    }
}