// Arup Guha
// 1/29/2015
// Solution to 2013 MCPC Problem D: Probability Paradox

import java.util.*;

public class d {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		String win = stdin.next();

        // Go through all cases.
		while (!win.equals("$")) {

			String lose = stdin.next();
			TreeSet<String> states = new TreeSet<String>();

			// Add in each prefix of the winning string as a possible state to our graph.
			for (int i=0; i<=win.length(); i++)
				states.add(win.substring(0, i));

			// Same for losing states.
			for (int i=1; i<=lose.length(); i++)
				states.add(lose.substring(0, i));

			// Copy strings into array.
			String[] vars = new String[states.size()];
			for (int i=0; i<vars.length; i++)
				vars[i] = states.pollFirst();

			// Make a reverse look up table.
			HashMap<String,Integer> lookup = new HashMap<String,Integer>();
			for (int i=0; i<vars.length; i++)
				lookup.put(vars[i], i);

			// Creates the corresponding set of equations with these sets of states.
			fraction[][] eqns = getEqns(vars, lookup, win);

			// Get all solutions and then output the one we want.
			fraction[] soln = solve(eqns);
			System.out.println(soln[lookup.get("")]);

			// Get next case.
			win = stdin.next();
		}
	}

	// Does Gaussian elimination to solve the system.
	public static fraction[] solve(fraction[][] eqns) {

		int n = eqns.length;

		// Go through each row, looking to put "best" row in this position
		// before using to reduce all other equations.
		for (int i=0; i<n; i++) {
			int row = findBest(eqns, i);
			swapRows(eqns, row, i);
			reduce(eqns, i);
		}

		// Now, backsubstitute.
		fraction[] ans = new fraction[n];
		for (int i=n-1; i>=0; i--)
			update(eqns, ans, i);

		// Ta da!
		return ans;
	}

	public static int findBest(fraction[][] eqns, int startRow) {

		// Look for pivot coefficient - max in column start row from this point on.
		int res = startRow;
		for (int i=startRow+1; i<eqns.length; i++)
			if (eqns[i][startRow].abs().compareTo(eqns[res][startRow].abs()) > 0)
				res = i;

		// Return its index.
		return res;
	}

	// Since these are all references, we can swap efficiently.
	public static void swapRows(fraction[][] eqns, int i, int j) {
		fraction[] tmp = eqns[i];
		eqns[i] = eqns[j];
		eqns[j] = tmp;
	}

	public static void reduce(fraction[][] eqns, int startRow) {

		// Reduce each of these rows.
		for (int row = startRow+1; row<eqns.length; row++) {
			fraction factor = eqns[row][startRow].divide(eqns[startRow][startRow]);

			// Change each number on this row, accordingly.
			for (int col=startRow; col<eqns[row].length; col++)
				eqns[row][col] = eqns[row][col].subtract( factor.multiply(eqns[startRow][col]) );
		}
	}

	public static void update(fraction[][] eqns, fraction[] ans, int row) {

		int n = eqns.length;

		// Add up terms for terms after row, that we already have answers for.
		fraction cur = new fraction(0, 1);
		for (int i=row+1; i<eqns.length; i++)
			cur = cur.add( eqns[row][i].multiply(ans[i]) );

		// Here is our solution for this variable.
		ans[row] = (eqns[row][n].subtract(cur)).divide(eqns[row][row]);
	}

	public static fraction[][] getEqns(String[] vars, HashMap<String,Integer> lookup, String win) {

		// Initialize coefficients to all zeros.
		int n = vars.length;
		fraction[][] eqns = new fraction[n][n+1];
		for (int i=0; i<n; i++)
			for (int j=0; j<n+1; j++)
				eqns[i][j] = new fraction(0,1);

		// Set up each equation.
		for (int i=0; i<n; i++) {

			// This coefficient is always 1.
			eqns[i][i] = new fraction(1, 1);

			// Special case - end states.
			if (vars[i].length() == win.length()) {
				if (vars[i].equals(win)) 	eqns[i][n] = new fraction(1, 1);
			}

			// Deal with regular case here - two next states are always -1/2.
			else {
				eqns[i][findNext(vars[i]+"T", lookup)] = eqns[i][findNext(vars[i]+"T", lookup)].add(new fraction(-1, 2));
				eqns[i][findNext(vars[i]+"H", lookup)] = eqns[i][findNext(vars[i]+"H", lookup)].add(new fraction(-1, 2));
			}
		}

		return eqns;
	}

	// Returns the state in lookup that matches state. (Returns the longest suffix of
	// state that is a key in lookup...which corresponds to transitions in the state
	// diagram for the problem.
	public static int findNext(String state, HashMap<String,Integer> lookup) {
		while (!lookup.containsKey(state)) state = state.substring(1);
		return lookup.get(state);
	}
}

// A typical fraction class.
class fraction {

	public long num;
	public long den;

	public fraction(long n,long d) {
		long common = gcd(n,d);
		num = n/common;
		den = d/common;

		if (den < 0) {
			num = -num;
			den = -den;
		}
	}

	public fraction add(fraction other) {
		long n = this.num*other.den + other.num*this.den;
		long d = this.den*other.den;
		return new fraction(n,d);
	}

	public fraction subtract(fraction other) {
		long n = this.num*other.den - other.num*this.den;
		long d = this.den*other.den;
		return new fraction(n,d);
	}

	public fraction multiply(fraction other) {
		long n = this.num*other.num;
		long d = this.den*other.den;
		return new fraction(n,d);
	}

	public fraction divide(fraction other) {
		long n = this.num*other.den;
		long d = this.den*other.num;
		return new fraction(n,d);
	}

	public static long gcd(long a, long b) {
		if (a == 0) return b;
		if (b == 0) return a;
		if (a < 0 || b < 0) return gcd(Math.abs(a), Math.abs(b));
		return gcd(b, a%b);
	}

	public String toString() {
		return num+"/"+den;
	}

	public fraction abs() {
		return new fraction(Math.abs(num), Math.abs(den));
	}

	public int compareTo(fraction other) {
		if (this.num*other.den == this.den*other.num) return 0;
		if (this.den*other.den > 0) return (this.num*other.den > this.den*other.num) ? 1 : -1;
		else 		 				return (this.num*other.den < this.den*other.num) ? 1 : -1;
	}
}
