// #[rustfmt::skip] // pub mod lib {pub use ac_library::*;pub use itertools::{join, Combinations, Itertools, MultiProduct, Permutations};pub use proconio::{input,marker::{Chars, Usize1}};pub use std::{cmp::*, collections::*, mem::swap};pub use regex::Regex;pub use superslice::Ext;pub use num_traits::{One, ToPrimitive, FromPrimitive, PrimInt};#[macro_export]macro_rules! degg {($($val:expr),+ $(,)?) => {println!("[{}:{}] {}",file!(),line!(),{let mut parts = Vec::new();$(parts.push(format!("{} = {:?}", stringify!($val), &$val));)+parts.join(", ")})}}} // use lib::*; use std::collections::{HashMap, HashSet}; use proconio::{input, marker::Usize1}; fn main() { input! { x: usize, y: usize, n: usize, uv: [(usize, usize); n] } for &(u, v) in uv.iter() { if u == 0 { let v = (v - 1) % y + 1; println!("{}", v); continue; } let uu = (u - 1) / y; let vv = (v - 1) / y; if uu == vv { let ans = u.abs_diff(v); println!("{}", ans); continue; } let uu = (u - 1) % y + 1; let vv = (v - 1) % y + 1; println!("{}", uu + vv); } }