#!/usr/bin/ruby
# coding: utf-8

PI = Math.acos(-1)

n = gets.to_i
gets.to_i.times do |i|
  j,i = gets.chomp.split(' ').map { |x| x.to_i }
  i = [i, j, n-i+1, n-j+1].min
  mod = (i+2) % 3
  puts(mod + 1)
end