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

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

j = A("j")
i = B("i")
d = A("d")
n = A("n")
f = A("f")
a = A("a")
e = B("e")
g = A("g")
m = A("m")
h = B("h")

j.u = i
i.r = g
i.w = h
d.u = i
n.u = e
f.u = h
a.u = i
e.r = j
e.w = h
g.u = h
m.u = e
h.r = a
h.w = e
assert d.u.r.u.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

j = A("j")
i = B("i")
d = A("d")
n = A("n")
f = A("f")
a = A("a")
e = B("e")
g = A("g")
m = A("m")
h = B("h")

j.u = i
i.r = g
i.w = h
d.u = i
n.u = e
f.u = h
a.u = i
e.r = j
e.w = h
g.u = h
m.u = e
h.r = a
h.w = e
assert d.u.r.u.w.w.w.txt == "e"