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

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

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

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

n.y = c
j.q = c
j.z = a
c.t = j
c.o = a
c.z = a
a.y = c
assert n.y.z.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

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

n.y = c
j.q = c
j.z = a
c.t = j
c.o = a
c.z = a
a.y = c
assert n.y.z.y.txt == "c"