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

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

e = A("e")
f = B("f")
b = B("b")
m = A("m")
n = B("n")

e.w = m
e.p = m
f.y = b
b.y = n
m.w = e
m.p = e
n.y = f
assert b.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.p: A = None
        self.txt = txt

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

e = A("e")
f = B("f")
b = B("b")
m = A("m")
n = B("n")

e.w = m
e.p = m
f.y = b
b.y = n
m.w = e
m.p = e
n.y = f
assert b.y.y.y.y.y.txt == "f"