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

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

e = A("e")
d = B("d")
h = B("h")
m = A("m")
a = B("a")

e.r = m
e.t = m
d.s = m
d.x = e
h.s = m
h.x = e
m.r = e
m.t = e
a.s = e
a.x = e
assert m.t.r.t.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.t: A = None
        self.txt = txt

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

e = A("e")
d = B("d")
h = B("h")
m = A("m")
a = B("a")

e.r = m
e.t = m
d.s = m
d.x = e
h.s = m
h.x = e
m.r = e
m.t = e
a.s = e
a.x = e
assert m.t.r.t.r.r.txt == "e"