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

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

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

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

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

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

h.r = m
h.x = i
a.w = i
e.w = f
b.w = i
f.w = i
d.r = m
d.x = i
m.r = n
m.x = f
n.r = m
n.x = b
i.w = e
assert d.r.x.w.txt == "i"