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

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

n = A("n")
l = B("l")
d = B("d")
a = A("a")
k = A("k")
e = A("e")
j = A("j")
c = A("c")
f = A("f")

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

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

n = A("n")
l = B("l")
d = B("d")
a = A("a")
k = A("k")
e = A("e")
j = A("j")
c = A("c")
f = A("f")

n.r = f
n.s = f
l.x = n
l.w = n
d.x = f
d.w = f
a.r = c
a.s = e
k.r = e
k.s = j
e.r = c
e.s = j
j.r = c
j.s = c
c.r = f
c.s = e
f.r = n
f.s = c
assert f.s.r.r.r.s.txt == "c"