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

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

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

k = A("k")
e = B("e")
b = C("b")
h = C("h")
f = C("f")
c = B("c")
a = A("a")
l = C("l")
j = C("j")

k.r = e
k.p = a
k.w = a
e.r = c
e.p = c
e.s = a
b.x = e
h.x = c
f.x = c
c.r = e
c.p = e
c.s = k
a.r = c
a.p = k
a.w = k
l.x = e
j.x = e
assert c.s.r.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.p: A = None
        self.w: A = None
        self.txt = txt

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

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

k = A("k")
e = B("e")
b = C("b")
h = C("h")
f = C("f")
c = B("c")
a = A("a")
l = C("l")
j = C("j")

k.r = e
k.p = a
k.w = a
e.r = c
e.p = c
e.s = a
b.x = e
h.x = c
f.x = c
c.r = e
c.p = e
c.s = k
a.r = c
a.p = k
a.w = k
l.x = e
j.x = e
assert c.s.r.s.r.txt == "c"