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

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

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

m = A("m")
k = B("k")
d = C("d")
b = B("b")
l = A("l")
e = B("e")
j = A("j")
h = B("h")
i = B("i")
f = B("f")

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

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

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

m = A("m")
k = B("k")
d = C("d")
b = B("b")
l = A("l")
e = B("e")
j = A("j")
h = B("h")
i = B("i")
f = B("f")

m.q = j
k.v = d
d.v = f
b.v = d
l.q = m
e.v = d
j.q = l
h.v = d
i.v = d
f.v = d
assert h.v.v.v.v.txt == "f"