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

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

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

a = A("a")
f = B("f")
m = C("m")
j = A("j")
g = C("g")

a.p = f
a.t = f
a.q = m
f.z = j
f.x = m
m.q = f
j.p = f
j.t = f
j.q = m
g.q = f
assert g.q.z.q.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.t: B = None
        self.q: C = None
        self.txt = txt

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

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

a = A("a")
f = B("f")
m = C("m")
j = A("j")
g = C("g")

a.p = f
a.t = f
a.q = m
f.z = j
f.x = m
m.q = f
j.p = f
j.t = f
j.q = m
g.q = f
assert g.q.z.q.q.x.txt == "m"