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

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

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

h = A("h")
e = B("e")
a = C("a")
j = C("j")

h.t = j
h.r = a
e.p = h
e.u = h
e.w = h
a.r = e
a.v = h
a.q = h
j.r = e
j.v = h
j.q = h
assert j.v.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.r: C = None
        self.txt = txt

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

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

h = A("h")
e = B("e")
a = C("a")
j = C("j")

h.t = j
h.r = a
e.p = h
e.u = h
e.w = h
a.r = e
a.v = h
a.q = h
j.r = e
j.v = h
j.q = h
assert j.v.t.q.txt == "h"