I apologize in advance if this sounds vague but I am trying to find directions as to what to look for.

All the sets in this problem are finite. Suppose we have two functions $f_1\colon X_1\times Y_1\to X_1$ and $f_2\colon X_2\times Y_2\to X_2$.

**Problem**. Decide whether there exist two surjective mappings $p\colon X_2\to X_1$ and $q\colon Y_2\to Y_1$ satisfying the condition
$$
\forall x\in X_2, y\in Y_2 : p(f_2(x,y))= f_1(p(x), q(y))
$$

I looked into set-valued optimization and combinatorial set theory but it all seemed too complex for my problem. I have just started reading Kuratowski and Aubin's books. It looks like most optimization problems are formulated using differential inclusion one way or the other and that doesn't seem to be feasible in my case. To me it looks like a typical search problem, I am just not sure how to properly pose it using sets/mappings as variables. Any advice would be super helpful. I am looking into developing an algorithm that proves the existence of the mappings in polynomial time.