@classmethod
def matrix_pow(cls, a, n, mod=((10 ** 9) + 7)):
    m = len(a)
    b = cls.identity(m)
    while n:
        if (n & 1):
            b = cls.dot(b, a)
        n >>= 1
        a = cls.dot(a, a)
        if using_numpy:
            a %= mod
            b %= mod
        else:
            for i in range(m):
                for j in range(m):
                    a[i][j] %= mod
                    b[i][j] %= mod
    return b
@classmethod
def matrix_pow(cls, a, n, mod=((10 ** 9) + 7)):
    m = len(a)
    b = cls.identity(m)
    while n:
        if (n & 1):
            b = cls.dot(b, a)
        n >>= 1
        a = cls.dot(a, a)
        if using_numpy:
            a %= mod
            b %= mod
        else:
            for i in range(m):
                for j in range(m):
                    a[i][j] %= mod
                    b[i][j] %= mod
    return b