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

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

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

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

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

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

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

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

l.t = m
k.o = l
k.p = m
k.q = g
m.p = l
g.o = l
g.p = m
g.q = k
assert k.p.p.t.p.txt == "l"