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

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

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

c = A("c")
f = B("f")
m = C("m")
e = B("e")
k = A("k")
g = C("g")

c.p = k
c.r = k
c.s = k
f.w = m
f.u = k
m.x = e
e.w = g
e.u = k
k.p = c
k.r = c
k.s = c
g.x = e
assert k.p.r.s.p.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.r: A = None
        self.s: A = None
        self.txt = txt

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

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

c = A("c")
f = B("f")
m = C("m")
e = B("e")
k = A("k")
g = C("g")

c.p = k
c.r = k
c.s = k
f.w = m
f.u = k
m.x = e
e.w = g
e.u = k
k.p = c
k.r = c
k.s = c
g.x = e
assert k.p.r.s.p.r.p.txt == "k"