A convenient and useful way to represent topological surfaces is with a fundamental polygon. Each side on a polygon matches to another side and can be either parallel or anti-parallel. For instance the here is the fundamental polygon of a torus:
To figure out why this is a torus we could imagine our polygon being a sheet of paper. To make the proper surface we want to bend our paper so that the corresponding edges line up with their arrows going the same way. For our torus example we can start by rolling the paper into a cylinder so that the two blue edges (labeled b) are connected. Now we take our tube and bend it so that the two red edges (labeled a) connect to each other. We should have a donut shape, also called the torus.
This can get a bit trickier. If you try to do the same with the following polygon where one of the edges is going in the opposite direction:
you might find yourself in some trouble. This is because this polygon represents the Klein bottle which cannot be embedded in three dimensions. Here is a diagram from wikipedia showing how you can fold this polygon into a Klein bottle:
As you may have guessed the task here is to take a fundamental polygon and determine which surface it is. For four sided polygons (the only surfaces you will be required to handle) there are 4 different surfaces.
They are
Torus
Klein Bottle
Sphere
Projective plane
Now this is not image-processing so I don't expect you to take an image as input instead we will use a convenient notation to represent the fundamental polygon. You may have noticed in the two examples above that I named corresponding edges with the same letter (either a or b), and that I gave the twisted edge an additional mark to show its twisted. If we start at the upper edge and write down the label for each edge as we go clockwise we can get a notation that represents each fundamental polygon.
For example the Torus provided would become abab and the Klein Bottle would become ab-ab. For our challenge we will make it even simpler, instead of marking twisted edges with a negative we will instead make those letters capitalized.
Task
Given a string determine if it represents a fundamental polygon and output a value that corresponding to the proper surface of it is. You do not need to name the surfaces exactly, you just need 4 output distinct values each representing one of the 4 surfaces with a fifth value representing improper input. All of the basic cases are covered in the Simple Tests section, every car will be isomorphic to one of the or invalid.
Rules
Sides will not always be labeled with a and b, but they will always be labeled with letters.
Valid input will consist of 4 letters, two of one type and two of another. You must always output the correct surface for valid input.
You should reject (not output any of the 4 values representing surfaces) invalid input. You may do anything when rejecting an input, as long as it is distinguishable from the 4 surfaces
This is code-golf so the goal is to minimize the number of bytes in your source code.
Tests
Simple Tests
abab Torus
abAb Klein Bottle
abaB Klein Bottle
abAB Projective Plane
aabb Klein Bottle
aAbb Projective Plane
aabB Projective Plane
aAbB Sphere
abba Klein Bottle
abBa Projective Plane
abbA Projective Plane
abBA Sphere
Trickier Tests
ABAB Torus
acAc Klein Bottle
Emme Projective Plane
zxXZ Sphere
aaab Bad input
abca Bad input
abbaa Bad input
ab1a Bad input
abab
a torus andaabb
a Klein bottle? \$\endgroup\$abab
is the example in the first paragraph, you can look there for an explanation. Here is an image showing whyaabb
is the same asabAb
which is a Klein bottle. \$\endgroup\$