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

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

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

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

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

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

b.r = i
b.w = e
e.w = i
e.x = b
j.r = i
j.w = d
m.r = i
m.w = d
h.r = i
h.w = d
d.w = e
d.x = h
g.r = e
g.w = i
n.r = i
n.w = e
i.w = e
i.x = h
assert h.r.x.r.w.x.r.x.txt == "h"