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

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

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

b = A("b")
c = B("c")
j = C("j")
m = A("m")

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

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

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

b = A("b")
c = B("c")
j = C("j")
m = A("m")

b.q = j
b.x = m
b.z = m
c.t = b
c.p = j
j.t = b
m.q = j
m.x = b
m.z = b
assert b.z.x.q.txt == "j"