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

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

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

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

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

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

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

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

a.p = k
a.x = k
a.r = c
k.s = c
k.r = f
b.u = l
b.y = f
b.x = a
l.u = b
l.y = k
l.x = a
c.p = k
c.r = a
c.x = f
f.s = c
f.r = k
assert k.s.x.s.r.x.txt == "k"