class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.y: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.w: A = None
        self.s: A = None
        self.txt = txt

f = A("f")
m = B("m")
e = A("e")
a = B("a")
j = A("j")

f.s = j
f.y = j
m.w = j
m.s = f
e.s = j
e.y = f
a.w = e
a.s = f
j.s = f
j.y = f
assert a.w.y.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.y: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.w: A = None
        self.s: A = None
        self.txt = txt

f = A("f")
m = B("m")
e = A("e")
a = B("a")
j = A("j")

f.s = j
f.y = j
m.w = j
m.s = f
e.s = j
e.y = f
a.w = e
a.s = f
j.s = f
j.y = f
assert a.w.y.s.s.txt == "f"