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

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

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

i = A("i")
k = B("k")
e = C("e")
a = C("a")
d = C("d")

i.s = e
i.p = k
k.x = e
e.s = k
e.q = i
a.s = k
a.q = i
d.s = k
d.q = i
assert a.s.x.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.p: B = None
        self.txt = txt

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

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

i = A("i")
k = B("k")
e = C("e")
a = C("a")
d = C("d")

i.s = e
i.p = k
k.x = e
e.s = k
e.q = i
a.s = k
a.q = i
d.s = k
d.q = i
assert a.s.x.s.x.txt == "e"