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

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

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

j = A("j")
i = B("i")
h = C("h")

j.p = h
j.q = h
i.u = h
i.p = h
i.t = j
h.s = j
h.q = i
assert j.q.s.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.q: C = None
        self.txt = txt

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

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

j = A("j")
i = B("i")
h = C("h")

j.p = h
j.q = h
i.u = h
i.p = h
i.t = j
h.s = j
h.q = i
assert j.q.s.q.txt == "h"