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

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

m = A("m")
j = B("j")
a = A("a")
f = A("f")
n = B("n")
h = A("h")

m.z = h
m.r = n
j.t = a
a.z = m
a.r = n
f.z = a
f.r = j
n.t = m
h.z = m
h.r = n
assert m.r.t.r.t.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.r: B = None
        self.txt = txt

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

m = A("m")
j = B("j")
a = A("a")
f = A("f")
n = B("n")
h = A("h")

m.z = h
m.r = n
j.t = a
a.z = m
a.r = n
f.z = a
f.r = j
n.t = m
h.z = m
h.r = n
assert m.r.t.r.t.z.z.txt == "m"