Correspond the elements of $A$ with integer pairs $\bmod 2011$.
Let $h((a_0, a_1), (b_0, b_1)) = (a_0 - b_0) \cdot (a_1 - b_1)^{-1}$, again taking the inverse $\bmod 2011$. (note: 2011 is prime)
$h$ maps $A$ to a set of 2012 values: the integers $\bmod 2011$ and "undefined" when $a_1 = b_1$ (this is similar to the "body" of the order-2011 finite projective plane). Now assign one nonzero value to each element of $B$, and do whatever you like with 0 and "undefined" (we're picking these purely for convenience), to get the function $f$. ($f(x, x)$ can also be arbitrarily defined).
Now, to show this function satisfies the condition, let $g$ be a function mapping $A$ to $B$.
By pigeonhole, some element $b$ of $B$ has 2012 values mapping to it; let those values be $S$.
Let $h'((a_0, a_1)) = a_1b - a_0$. Observe that $h'((a_0, a_1)) = h'((b_0, b_1))$ iff $h((a_0, a_1), (b_0, b_1)) = b$ or $(a_0, a_1) = (b_0, b_1)$. By pigeonhole again, since $h'$ maps the elements of $S$ to a set of 2011 values, it has to map two distinct elements to the same value, and those elements are the pair the problem requests.