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

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

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

j = A("j")
n = B("n")
d = C("d")
a = A("a")

j.q = a
j.y = a
j.z = n
n.w = d
d.p = n
d.o = a
a.q = j
a.y = j
a.z = n
assert d.p.w.o.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.z: B = None
        self.y: A = None
        self.txt = txt

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

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

j = A("j")
n = B("n")
d = C("d")
a = A("a")

j.q = a
j.y = a
j.z = n
n.w = d
d.p = n
d.o = a
a.q = j
a.y = j
a.z = n
assert d.p.w.o.txt == "a"