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

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

e = A("e")
h = B("h")
g = A("g")
c = B("c")
m = B("m")
i = A("i")
b = A("b")

e.t = c
h.v = g
g.t = m
c.v = e
m.v = b
i.t = h
b.t = h
assert h.v.t.v.t.v.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

e = A("e")
h = B("h")
g = A("g")
c = B("c")
m = B("m")
i = A("i")
b = A("b")

e.t = c
h.v = g
g.t = m
c.v = e
m.v = b
i.t = h
b.t = h
assert h.v.t.v.t.v.t.txt == "m"