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

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

g = A("g")
k = B("k")
h = B("h")
b = A("b")
d = A("d")
l = B("l")
e = A("e")
f = B("f")

g.r = e
g.w = l
k.s = e
h.s = e
b.r = d
b.w = k
d.r = g
d.w = h
l.s = d
e.r = d
e.w = h
f.s = b
assert d.w.s.r.w.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.w: B = None
        self.txt = txt

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

g = A("g")
k = B("k")
h = B("h")
b = A("b")
d = A("d")
l = B("l")
e = A("e")
f = B("f")

g.r = e
g.w = l
k.s = e
h.s = e
b.r = d
b.w = k
d.r = g
d.w = h
l.s = d
e.r = d
e.w = h
f.s = b
assert d.w.s.r.w.s.w.txt == "h"