def groupOp(pair1, pair2, n1, n2):
    """Apply group operation to two pairs:
       (g1,h1) x (g2, h2) 
       G beeing multiplicative, H additive, thus
       (g1*g2 , h1+h2)"""
    return ((pair1[0] * pair2[0]) % n1, (pair1[1] + pair2[1]) % n2)