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

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

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

i = A("i")
j = B("j")
n = C("n")

i.o = n
j.p = i
j.y = i
j.q = n
n.o = j
assert n.o.y.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

i = A("i")
j = B("j")
n = C("n")

i.o = n
j.p = i
j.y = i
j.q = n
n.o = j
assert n.o.y.o.txt == "n"