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

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

e = A("e")
j = B("j")
m = A("m")
d = B("d")
a = B("a")
i = B("i")

e.x = m
j.t = d
j.w = m
m.x = e
d.t = a
d.w = m
a.t = i
a.w = m
i.t = a
i.w = m
assert e.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

e = A("e")
j = B("j")
m = A("m")
d = B("d")
a = B("a")
i = B("i")

e.x = m
j.t = d
j.w = m
m.x = e
d.t = a
d.w = m
a.t = i
a.w = m
i.t = a
i.w = m
assert e.x.x.x.x.x.txt == "m"