# mod(a,b) is a mod b;

mod(a_,b_,c_,d_):=powermod(a,b^c,d);
mod(a_,b_,c_):=powermod(a,b,c);
mod(a_ and b_,c_):=mod(a,c) and mod(b,c);
mod(a_^b_,c_):=powermod(a,b,c);