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

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

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

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

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

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

d.x = j
d.s = c
c.r = k
c.y = k
f.r = k
f.y = l
k.x = n
k.s = j
i.x = n
i.s = c
j.r = l
j.y = l
n.r = k
n.y = i
l.x = n
l.s = n
assert d.s.r.s.r.txt == "l"