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

class B:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

l = A("l")
g = B("g")
j = C("j")
b = A("b")
c = B("c")

l.p = j
l.o = c
g.r = b
j.s = c
j.z = b
b.p = j
b.o = c
c.r = l
assert l.o.r.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.o: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

l = A("l")
g = B("g")
j = C("j")
b = A("b")
c = B("c")

l.p = j
l.o = c
g.r = b
j.s = c
j.z = b
b.p = j
b.o = c
c.r = l
assert l.o.r.p.s.txt == "c"