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

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

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

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

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

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

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