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

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

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

l = A("l")
i = B("i")
f = C("f")
n = B("n")
j = C("j")
g = B("g")

l.p = j
i.s = n
i.p = n
i.w = l
f.r = l
n.s = g
n.w = l
n.p = i
j.r = l
g.s = n
g.w = l
g.p = i
assert l.p.r.p.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

l = A("l")
i = B("i")
f = C("f")
n = B("n")
j = C("j")
g = B("g")

l.p = j
i.s = n
i.p = n
i.w = l
f.r = l
n.s = g
n.w = l
n.p = i
j.r = l
g.s = n
g.w = l
g.p = i
assert l.p.r.p.r.p.txt == "j"