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

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

m = A("m")
l = B("l")
e = A("e")
d = B("d")

m.p = d
m.s = e
l.y = d
e.p = d
e.s = m
d.y = l
assert d.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.s: A = None
        self.txt = txt

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

m = A("m")
l = B("l")
e = A("e")
d = B("d")

m.p = d
m.s = e
l.y = d
e.p = d
e.s = m
d.y = l
assert d.y.y.y.txt == "l"