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

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

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

b = A("b")
i = B("i")
l = C("l")
m = B("m")

b.s = l
b.y = l
b.p = m
i.r = l
i.x = b
i.p = b
l.u = m
l.x = b
m.r = l
m.x = b
m.p = b
assert i.r.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.y: C = None
        self.p: B = None
        self.txt = txt

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

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

b = A("b")
i = B("i")
l = C("l")
m = B("m")

b.s = l
b.y = l
b.p = m
i.r = l
i.x = b
i.p = b
l.u = m
l.x = b
m.r = l
m.x = b
m.p = b
assert i.r.x.p.txt == "m"