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

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

m = A("m")
a = B("a")
k = A("k")
c = B("c")
e = A("e")
n = A("n")
d = B("d")
h = B("h")
j = B("j")

m.x = e
a.q = e
k.x = n
c.q = k
e.x = m
n.x = e
d.q = n
h.q = k
j.q = m
assert d.q.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.q: A = None
        self.txt = txt

m = A("m")
a = B("a")
k = A("k")
c = B("c")
e = A("e")
n = A("n")
d = B("d")
h = B("h")
j = B("j")

m.x = e
a.q = e
k.x = n
c.q = k
e.x = m
n.x = e
d.q = n
h.q = k
j.q = m
assert d.q.x.x.x.x.x.txt == "e"