You can model this problem as a 0/1 Knapsack problem by splitting the $i$-th item $q_i$ times. Let the maximum value in $Q$ be $K$, then the typical 0/1 Knapsack solves the problem in $O(MNK)$ time.
For simplicity, suppose $q_i$ can be written as $1+2+\dots + j$. Then we can split the $i$-th item into new items of price $1\cdot p_i, 2\cdot p_i, \dots , j\cdot p_i$. The powerful thing about this way of splitting is that there is a combination of items to form $1$ to $q_i$. For example, if $q_i=10$ and we split into item {$1, 2, 3, 4\}$, we can form $6$ using $4+2$, $9$ using $4+3+2$ and so on. Therefore, 0/1 Knapsack will still gives a correct answer. If $q_i$ cannot be represented as sum of consecutive natural numbers, find the largest $j$ such that $q_i\geq \sum_{x=1}^j x$ and $r$ be remainder, then split $q_i$ into $\{1,2,\dots ,j, r\}$. Now each item gives $O(\sqrt M)$ more items in the 0/1 Knapsack, hence our solution now becomes $O(MN\sqrt{K})$.
We can further improve this by using the splitting strategy using power of two's $\{1, 2, 4, 8,\dots\}$. Then each item know gives only $O(\lg K)$ new items and our overall solution becomes $O(MN\log K)$.