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

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

b = A("b")
m = B("m")
j = A("j")
h = A("h")
e = A("e")
d = A("d")
i = A("i")

b.v = d
m.v = i
j.v = b
h.v = i
e.v = i
d.v = e
i.v = e
assert i.v.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

b = A("b")
m = B("m")
j = A("j")
h = A("h")
e = A("e")
d = A("d")
i = A("i")

b.v = d
m.v = i
j.v = b
h.v = i
e.v = i
d.v = e
i.v = e
assert i.v.v.v.v.v.txt == "e"