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

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

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

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

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

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

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