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

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

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

l = A("l")
c = B("c")
k = C("k")
i = C("i")
d = B("d")
n = A("n")
b = A("b")
g = C("g")
a = B("a")
e = C("e")

l.r = i
l.w = n
c.y = n
c.p = d
k.x = b
i.x = n
d.y = b
d.p = a
n.r = g
n.w = l
b.r = i
b.w = n
g.x = n
a.y = l
a.p = c
e.x = l
assert d.y.r.x.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.w: A = None
        self.txt = txt

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

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

l = A("l")
c = B("c")
k = C("k")
i = C("i")
d = B("d")
n = A("n")
b = A("b")
g = C("g")
a = B("a")
e = C("e")

l.r = i
l.w = n
c.y = n
c.p = d
k.x = b
i.x = n
d.y = b
d.p = a
n.r = g
n.w = l
b.r = i
b.w = n
g.x = n
a.y = l
a.p = c
e.x = l
assert d.y.r.x.w.w.txt == "n"