TYPING - Chef and Typing Problem

Can anyone please see my code and tell me whats the problem. I have checked for all the test cases, but still, I m getting the wrong answer.

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

    
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner s = new Scanner(System.in);
		int t = s.nextInt();
		HashMap<String, Long> words = new HashMap<>();
		ArrayList<String> arr=new ArrayList<>();
		for (int i = 0; i < t; i++) {
		    long total_cost=0;
			int n = s.nextInt();
			for (int j = 0; j < n; j++) {
				String str = s.next();
				total_cost+=cost(words,str);
			}
			System.out.println(total_cost);
		}
	}
	
	public static long cost(HashMap<String,Long> words,String str){
	    //Set<Map.Entry<String, Integer>> word = words.entrySet();
	    if(words.containsKey(str))
	        return words.get(str)/2;
		//long total_cost = 0;
		
	        long str_cost = 2;

			for (int i = 1; i < str.length(); i++) {
			    char c1=str.charAt(i-1);
			    char c2=str.charAt(i);
				if((c1=='d'||c1=='f')&&(c2=='d'||c2=='f'))  str_cost+=4;
				if((c1=='d'||c1=='f')&&(c2=='j'||c2=='k'))  str_cost+=2;
				if((c1=='j'||c1=='k')&&(c2=='j'||c2=='k'))  str_cost+=4;
				if((c1=='j'||c1=='k')&&(c2=='d'||c2=='f'))  str_cost+=2;
			}
			
		words.put(str,str_cost);
		return str_cost;
	}
}