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

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

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

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

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

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

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