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

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

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

d = A("d")
a = B("a")
m = C("m")
i = A("i")
h = A("h")
b = C("b")

d.s = h
a.u = m
m.z = a
m.v = a
m.q = i
i.s = h
h.s = i
b.z = a
b.v = a
b.q = h
assert i.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

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

d = A("d")
a = B("a")
m = C("m")
i = A("i")
h = A("h")
b = C("b")

d.s = h
a.u = m
m.z = a
m.v = a
m.q = i
i.s = h
h.s = i
b.z = a
b.v = a
b.q = h
assert i.s.s.s.s.txt == "i"