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

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

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

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

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

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

d.v = e
e.v = m
f.v = m
m.v = e
l.v = f
assert m.v.v.v.txt == "e"