#include<bits/stdc++.h>
#define S second 
#define F first
#define all(x) x.begin(),x.end()
#define debug(x) cout<<x<<":"<<#x<<"\n";
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef long double ld;
ll inf = 1000000ll*1000000*1000000*4;
ll mod = 998244353;
const int maxn = 1024;
int Ls[maxn];
int Lt[maxn];
string s,t;
ll dp[maxn][maxn][2],ans;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>s>>t;
	int last = 0;
	Ls[0] = 1;
	Lt[0] = 1;
	for(int i=1;i<s.size();i++){
		if(s[i] == s[i-1])last = i;
		Ls[i] = i-last+1;
	}
	last = 0;
	for(int i=1;i<t.size();i++){
		if(t[i] == t[i-1])last = i;
		Lt[i] = i-last+1;
	}
	/*for(int i=0;i<s.size();i++){
		cout<<Ls[i]<<" ";
	}cout<<"\n";
	for(int i=0;i<t.size();i++){
		cout<<Lt[i]<<" ";
	}cout<<"\n";*/
	for(int i=0;i<s.size();i++){
		for(int j=0;j<t.size();j++){
			if(i){
				dp[i][j][0] += dp[i-1][j][0]*(s[i] != s[i-1])+dp[i-1][j][1]*(s[i] != t[j]);
			}
			if(j){
				dp[i][j][1] += dp[i][j-1][1]*(t[j] != t[j-1])+dp[i][j-1][0]*(s[i] != t[j]);
			}
			dp[i][j][0] += Lt[j]*(s[i] != t[j]);
			dp[i][j][1] += Ls[i]*(s[i] != t[j]);
			dp[i][j][0] %= mod;
			dp[i][j][1] %= mod;
			ans += dp[i][j][0]+dp[i][j][1];
			ans %= mod;
		}
	}
	cout<<ans;
	return 0;
}
