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

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

m = A("m")
f = B("f")
e = B("e")
c = A("c")
n = B("n")

m.q = f
m.x = c
f.q = m
f.u = c
e.q = m
e.u = m
c.q = e
c.x = m
n.q = m
n.u = c
assert n.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.x: A = None
        self.txt = txt

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

m = A("m")
f = B("f")
e = B("e")
c = A("c")
n = B("n")

m.q = f
m.x = c
f.q = m
f.u = c
e.q = m
e.u = m
c.q = e
c.x = m
n.q = m
n.u = c
assert n.q.q.q.q.txt == "f"