#import <Foundation/Foundation.h>

@interface NSString (Extension)
-(NSInteger)countOfSubstring:(NSString *)pattern;
@end

@implementation NSString (Extension)
-(NSInteger)countOfSubstring:(NSString *)pattern
{
	NSMutableArray *matchingRanges = [NSMutableArray new];
	NSUInteger textLength = self.length;
	NSRange match = NSMakeRange(0, self.length);
	NSInteger count = 0;
	while(match.location != NSNotFound) {
		match = [self rangeOfString:pattern options:0L range:match];
		if (match.location != NSNotFound) {
			count++;
			match = NSMakeRange(match.location+1, self.length - match.location - 1);
		}
	}

	return count;
}
@end

int main() {
	@autoreleasepool {
		int n;
		int ans = 0;
		scanf("%d",&n);
		int x=0,y=0,z=0;
		for(int i=0;i<n;i++){
			char s[20];
			scanf("%s",s);
			NSString *S = [NSString stringWithUTF8String:s];
			NSInteger count = [S countOfSubstring:@"AB"];
			ans += count;
			char f = s[0];
			char l = s[strlen(s)-1];
			if(f=='B' && l!='A') x++;
			if(f!='B' && l=='A') y++;
			if(f=='B' && l=='A') z++;
		}
		if (z>=1) {
			ans += z-1;
			z = 1;
		}
		if(x==y){
			ans += x;
		}else{
			ans += MIN(x,y) + z;
		}
		printf("%d\n",ans);
	}
}
