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

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

e = A("e")
g = B("g")
h = A("h")
a = A("a")
n = B("n")
m = B("m")

e.z = h
g.q = m
h.z = a
a.z = e
n.q = m
m.q = n
assert m.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

e = A("e")
g = B("g")
h = A("h")
a = A("a")
n = B("n")
m = B("m")

e.z = h
g.q = m
h.z = a
a.z = e
n.q = m
m.q = n
assert m.q.q.q.txt == "n"