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

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

d = A("d")
f = B("f")
h = A("h")
c = A("c")
n = B("n")
g = B("g")
e = B("e")
j = B("j")
i = A("i")
b = B("b")

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

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

d = A("d")
f = B("f")
h = A("h")
c = A("c")
n = B("n")
g = B("g")
e = B("e")
j = B("j")
i = A("i")
b = B("b")

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