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

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

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

n = A("n")
g = B("g")
k = C("k")
b = C("b")
j = B("j")

n.r = b
g.w = j
g.p = j
k.r = b
b.r = k
j.w = g
j.p = g
assert b.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

n = A("n")
g = B("g")
k = C("k")
b = C("b")
j = B("j")

n.r = b
g.w = j
g.p = j
k.r = b
b.r = k
j.w = g
j.p = g
assert b.r.r.r.r.r.txt == "k"