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

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

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

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

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

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

n.y = m
d.v = m
l.y = d
m.v = d
assert m.v.v.v.txt == "d"