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

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

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

m = A("m")
k = B("k")
d = C("d")
l = A("l")

m.o = k
m.t = l
m.q = d
k.p = d
d.s = k
d.p = k
d.x = m
l.o = k
l.t = m
l.q = d
assert d.x.q.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.t: A = None
        self.q: C = None
        self.txt = txt

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

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

m = A("m")
k = B("k")
d = C("d")
l = A("l")

m.o = k
m.t = l
m.q = d
k.p = d
d.s = k
d.p = k
d.x = m
l.o = k
l.t = m
l.q = d
assert d.x.q.x.q.txt == "d"