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

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

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

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

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

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

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