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

j = A("j")
d = B("d")
h = B("h")
g = A("g")
c = A("c")
a = B("a")
m = B("m")

j.v = h
d.v = m
h.v = d
g.v = a
c.v = d
a.v = h
m.v = a
assert c.v.v.v.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

j = A("j")
d = B("d")
h = B("h")
g = A("g")
c = A("c")
a = B("a")
m = B("m")

j.v = h
d.v = m
h.v = d
g.v = a
c.v = d
a.v = h
m.v = a
assert c.v.v.v.v.v.v.txt == "m"