Using fhevm isnt giving me the expected results, gives error sometimes

i have been working on a project which uses an Encrypted 2d matrix, with 4X4 matrix i get the expected results, but in my project i need to use a 7X7 matrix, if i use it then Rpc error is generated,
ill be sharing my code with you for more convenience,

function store() public {
        init = 0;
        depth = TFHE.asEuint32(1);
        a = TFHE.asEuint32(2);
        b = TFHE.asEuint32(3);
        m =  [
                  [TFHE.asEuint32(0),TFHE.asEuint32(1),TFHE.asEuint32(1),TFHE.asEuint32(1)],
                  [TFHE.asEuint32(1),TFHE.asEuint32(0),TFHE.asEuint32(1),TFHE.asEuint32(0)],
                  [TFHE.asEuint32(1),TFHE.asEuint32(1),TFHE.asEuint32(0),TFHE.asEuint32(0)],
                  [TFHE.asEuint32(1),TFHE.asEuint32(0),TFHE.asEuint32(0),TFHE.asEuint32(0)]];
        for (uint i = 0; i < 4; i++) {
            r[i] = TFHE.randEuint32();
            t[i] = TFHE.randEuint32();
        }
        distance=[0,1,1,1];
        iv = TFHE.asEuint32(0);

    }
   function setDiag() public{
    for(uint i=0; i<4 ; i++)
    {   
            m[i][i]=TFHE.select(affected[i],TFHE.add(TFHE.add(a,b),TFHE.add(r[i],t[i])),TFHE.add(a,TFHE.add(r[i],t[i])));
        }
   }
 function ivCal() public returns(euint32) {
    for(uint i=0;i<4;i++){
        iv =TFHE.add(iv,(TFHE.div(TFHE.mul(TFHE.sub(m[i][i],a),uint32((1 * 100000)/(2 ** distance[i]))),100)));
    }
    for(uint i=0;i<4;i++)
    {
        iv =TFHE.sub(iv,TFHE.div(TFHE.add(TFHE.mul(r[i],uint32(1*100000 /(2**distance[i]))),(TFHE.mul(t[i],uint32((1*100000)/(2**distance[i]))))),100));
    }
     iv=TFHE.div(iv,TFHE.decrypt(b));
    return iv;
}

this code is giving me the expected results, but when i change the 2d array to 7X7 wwhich the actual requirement of my project, it shows wrong values or rpc error, here’s the 7X7 code:

function store() public {
        init = 0;
        depth = TFHE.asEuint32(3);
        a = TFHE.asEuint32(2);
        b = TFHE.asEuint32(3);
        m = [
            [TFHE.asEuint32(0), TFHE.asEuint32(1), TFHE.asEuint32(1), TFHE.asEuint32(1), TFHE.asEuint32(0), TFHE.asEuint32(0), TFHE.asEuint32(0)],
            [TFHE.asEuint32(1), TFHE.asEuint32(0), TFHE.asEuint32(1), TFHE.asEuint32(0), TFHE.asEuint32(0), TFHE.asEuint32(0), TFHE.asEuint32(0)],
            [TFHE.asEuint32(1), TFHE.asEuint32(1), TFHE.asEuint32(0), TFHE.asEuint32(1), TFHE.asEuint32(1), TFHE.asEuint32(0), TFHE.asEuint32(0)],
            [TFHE.asEuint32(1), TFHE.asEuint32(0), TFHE.asEuint32(1), TFHE.asEuint32(0), TFHE.asEuint32(1), TFHE.asEuint32(0), TFHE.asEuint32(0)],
            [TFHE.asEuint32(0), TFHE.asEuint32(0), TFHE.asEuint32(1), TFHE.asEuint32(1), TFHE.asEuint32(0), TFHE.asEuint32(1), TFHE.asEuint32(1)],
            [TFHE.asEuint32(0), TFHE.asEuint32(0), TFHE.asEuint32(0), TFHE.asEuint32(0), TFHE.asEuint32(1), TFHE.asEuint32(0), TFHE.asEuint32(0)],
            [TFHE.asEuint32(0), TFHE.asEuint32(0), TFHE.asEuint32(0), TFHE.asEuint32(0), TFHE.asEuint32(1), TFHE.asEuint32(0), TFHE.asEuint32(0)]
        ];
 distance=[0,1,1,1,2,3,3];
        for (uint i = 0; i < 7; i++) {
            r[i] = TFHE.randEuint32();
            t[i] = TFHE.randEuint32();
        }
        iv = TFHE.asEuint32(0);
}
 function setDiag() public {
        for (uint i = 0; i < 7; i++) {
            m[i][i] = TFHE.select(affected[i], TFHE.add(TFHE.add(a, b), TFHE.add(r[i], t[i])), TFHE.add(a, TFHE.add(r[i], t[i])));
        }
    }
function ivCal() public returns(euint32) {
    for(uint i=0;i<7;i++){
        //uint i=1;
        iv =TFHE.add(iv,(TFHE.div(TFHE.mul(TFHE.sub(m[i][i],a),uint32((1 * 100000)/(2 ** distance[i]))),100)));
    }
    for(uint i=0;i<7;i++)
    {
        iv =TFHE.sub(iv,TFHE.div(TFHE.add(TFHE.mul(r[i],uint32(1*100000 /(2**distance[i]))),(TFHE.mul(t[i],uint32((1*100000)/(2**distance[i]))))),100));
    }
     iv=TFHE.div(iv,TFHE.decrypt(b));
     IV=TFHE.decrypt(iv);
    return iv;
    }

the error:

Gas estimation failed
Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
Returned error: {"jsonrpc":"2.0","error":"rpc error: code = Unknown desc = execution reverted","id":6595461375185809}

please look to this my deadline is very close.

First of all your code does not compile as it is not valid Solidity code. It would be easier if you gave us a valid snippet or link to a github repo containing at least code which compiles.
Secondly, did you try to force send your transaction? Your error suggests it is a problem in gas estimation. If you are using hardhat for your tests, set gasLimit to a high value such as {gasLimit: 5_000_000} in your function call in your hardhat test. There is a known issue with gas estimation in fhevm.