class A:
    def __init__(self, txt: str):
        self.q: B = 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: A = None
        self.txt = txt

i = A("i")
a = B("a")
l = C("l")
b = B("b")
h = C("h")
k = B("k")

i.q = a
a.v = l
l.v = i
b.v = h
h.v = i
k.v = h
assert a.v.v.q.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = 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: A = None
        self.txt = txt

i = A("i")
a = B("a")
l = C("l")
b = B("b")
h = C("h")
k = B("k")

i.q = a
a.v = l
l.v = i
b.v = h
h.v = i
k.v = h
assert a.v.v.q.v.v.txt == "i"