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

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

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

a = A("a")
h = B("h")
f = C("f")
n = B("n")

a.o = f
h.q = f
h.y = a
h.s = a
f.t = a
n.q = f
n.y = a
n.s = a
assert a.o.t.o.t.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

a = A("a")
h = B("h")
f = C("f")
n = B("n")

a.o = f
h.q = f
h.y = a
h.s = a
f.t = a
n.q = f
n.y = a
n.s = a
assert a.o.t.o.t.txt == "a"