How pools calculate rewards?
I mean they have PPLNS for 1 hour, after an hour they look into shares of the last hour and make rewards.

But here’s the question.
How they determine to give more rewards to C31 miners because they made fewer shares than C29.
Let’s assume we have two miners (C29 and C31) and for one hour we have:
C29 = 10000 shares,
C31 = 300 shares.

Depends on what is a share. If it’s a cycle whose cyclehash starts with a fixed number of 0 bits, then shares should be weighted by their scaling, which is secondary_scale for C29, graph_weight(height, 31) for C31, and graph_weight(height, 32) = 16384 for C32.

C31 is 15.28 weeks into its 30 week phaseout, so that would be 2^8 * (31-16) = 3840.
You can compute this 15.28 as (current_height - YEAR_HEIGHT) / WEEK_HEIGHT = (678173 - 524160) / 10080