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

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

d = A("d")
j = B("j")
e = A("e")
c = A("c")
i = A("i")
g = B("g")
m = B("m")
k = B("k")

d.s = e
d.r = c
j.s = e
j.w = k
e.s = i
e.r = i
c.s = i
c.r = e
i.s = e
i.r = c
g.s = e
g.w = k
m.s = d
m.w = k
k.s = d
k.w = g
assert d.r.s.r.r.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.r: A = None
        self.txt = txt

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

d = A("d")
j = B("j")
e = A("e")
c = A("c")
i = A("i")
g = B("g")
m = B("m")
k = B("k")

d.s = e
d.r = c
j.s = e
j.w = k
e.s = i
e.r = i
c.s = i
c.r = e
i.s = e
i.r = c
g.s = e
g.w = k
m.s = d
m.w = k
k.s = d
k.w = g
assert d.r.s.r.r.r.s.txt == "e"