(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro with-output-buffer (&body body)
  "Buffers all outputs to *STANDARD-OUTPUT* and flushes them to
*STANDARD-OUTPUT* at the end. Note that only BASE-CHAR is allowed."
  (let ((out (gensym)))
    `(let ((,out (make-string-output-stream :element-type 'base-char)))
       (let ((*standard-output* ,out))
         ,@body)
       (write-string (get-output-stream-string ,out)))))

(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  (declare #.OPT)
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  ;; (return-from read-fixnum 0)
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48) (the fixnum (* result 10))))
              (return (if minus (- result) result))))))))

(declaim (inline bisect-left))
(defun bisect-left (target value &key (start 0) end (test #'<) (key #'identity))
  "TARGET := vector | function
TEST := strict order

Returns the smallest index (or input) i that fulfills TARGET[i] >= VALUE, where
'>=' is the complement of TEST. TARGET must be monotonically non-decreasing with
respect to TEST. Returns END if VALUE exceeds TARGET[END-1]. Note that the range
[START, END) is half-open. END must be specified If TARGET is function. KEY is
applied to each element of TARGET before comparison."
  (declare (function key test)
           ((integer 0 #.most-positive-fixnum) start)
           ((or null (integer 0 #.most-positive-fixnum)) end))
  (macrolet
      ((body (accessor &optional declaration)
         `(cond ((assert (<= start end)))
                ((= start end) end)
                ((funcall test (funcall key (,accessor target (- end 1))) value)
                 end)
                (t (labels ((%bisect-left (l r)
                              ,@(list declaration)
                              (let ((mid (ash (+ l r) -1)))
                                (if (= mid l)
                                    (if (funcall test (funcall key (,accessor target l)) value)
                                        r
                                        l)
                                    (if (funcall test (funcall key (,accessor target mid)) value)
                                        (%bisect-left mid r)
                                        (%bisect-left l mid))))))
                     (%bisect-left start (- end 1)))))))
    (etypecase target
      (vector
       (let ((end (or end (length target))))
         (body aref (declare ((integer 0 #.most-positive-fixnum) l r)))))
      (function
       (assert end)
       (body funcall)))))

(defmacro nlet (name args &body body)
  (labels ((ensure-list (x) (if (listp x) x (list x))))
    (let ((args (mapcar #'ensure-list args)))
      `(labels ((,name ,(mapcar #'car args) ,@body))
         (,name ,@(mapcar #'cadr args))))))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (declare #.OPT)
  (let* ((a (read))
         (b (read))
         (q (read))
         (shrines (make-array a :element-type 'uint62))
         (temples (make-array b :element-type 'uint62)))
    (declare (uint31 a b q))
    (dotimes (i a)
      (setf (aref shrines i) (read-fixnum)))
    (dotimes (i b)
      (setf (aref temples i) (read-fixnum)))
    (labels ((bisect-find-t (spos)
               (declare (uint62 spos)
                        (values uint62))
               (let ((s (aref shrines spos)))
                 (nlet recurse ((l 0) (r b))
                   (declare (uint62 l r))
                   (if (<= (- r l) 1)
                       (min (abs (- s (aref temples l)))
                            (if (= r b)
                                most-positive-fixnum
                                (abs (- s (aref temples r)))))
                       (let ((mid (floor (+ r l) 2)))
                         (if (<= s (aref temples mid))
                             (recurse l mid)
                             (recurse mid r)))))))
             (bisect-find-s (tpos)
               (declare (uint62 tpos)
                        (values uint62))
               (let ((temple (aref temples tpos)))
                 (nlet recurse ((l 0) (r a))
                   (declare (uint62 l r))
                   (if (<= (- r l) 1)
                       (min (abs (- temple (aref shrines l)))
                            (if (= r a)
                                most-positive-fixnum
                                (abs (- temple (aref shrines r)))))
                       (let ((mid (floor (+ r l) 2)))
                         (if (<= temple (aref shrines mid))
                             (recurse l mid)
                             (recurse mid r))))))))
      (with-output-buffer
        (dotimes (i q)
          (let* ((x (read-fixnum))
                 (spos2 (min (- a 1) (bisect-left shrines x)))
                 (spos1 (max 0 (- spos2 1)))
                 (tpos2 (min (- b 1) (bisect-left temples x)))
                 (tpos1 (max 0 (- tpos2 1))))
            (declare (uint62 x))
            (println (the uint62
                          (min (+ (abs (- x (aref shrines spos2)))
                                  (bisect-find-t spos2))
                               (+ (abs (- x (aref shrines spos1)))
                                  (bisect-find-t spos1))
                               (+ (abs (- x (aref temples tpos2)))
                                  (bisect-find-s tpos2))
                               (+ (abs (- x (aref temples tpos1)))
                                  (bisect-find-s tpos1)))))))))))

#-swank(main)


Measured memory_bytes: 34788