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

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

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

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

j.t = d
j.p = g
j.x = i
d.z = i
d.q = g
i.w = h
h.z = i
h.q = g
g.t = h
g.p = j
g.x = i
assert g.p.x.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.p: A = None
        self.x: C = None
        self.txt = txt

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

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

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

j.t = d
j.p = g
j.x = i
d.z = i
d.q = g
i.w = h
h.z = i
h.q = g
g.t = h
g.p = j
g.x = i
assert g.p.x.w.q.txt == "g"