Array values get changed mysteriously

I am building two 2-D matrices for storing the number of times a character has occurred before and after a certain character. Basically, I am making a suffix array and a prefix array. For that, I wrote this code

#include <stdio.h>
#include <string.h>
#include <math.h>

int main()
{

long long t,i,j,k,n;
long long x,y,count;
scanf("%lld",&t);
char s[100000];
while(t--){
    y=0,count=0;
    scanf("%s",s);
    n=strlen(s);
    char suf[n][26];
    int columns=26;
    char pref[n][26];
    memset(pref, 0, sizeof(pref[0][0]) * n * columns);
    memset(suf, 0, sizeof(suf[0][0]) * n * columns);
    for(i=0;i<26;i++)
        suf[n-1][i]=0;
    for(i=n-1;i>0;i--)
        for(j=0;j<26;j++){
            if(j==s[i]-97)
            suf[i-1][j]=suf[i][j]+1;
            else
            suf[i-1][j]=suf[i][j];
        }

    for(i=0;i<26;i++)
        pref[0][i]=0;
    for(i=0;i<n;i++)
        for(j=0;j<26;j++)
        {
            if(j==s[i]-97)
            pref[i+1][j]=pref[i][j]+1;
            else
            pref[i+1][j]=pref[i][j];
        }

Okay. So, this gives me the first row of the suffix array incorrect. On the other hand, if I try building the suffix matrix after making the prefix matrix, the problem is solved. I just want to know that why did it happen even if I didn't touch the suffix matrix after building it.