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

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

g = A("g")
m = B("m")
j = A("j")
n = B("n")
e = B("e")

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

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

g = A("g")
m = B("m")
j = A("j")
n = B("n")
e = B("e")

g.q = m
g.u = m
m.q = g
j.q = n
j.u = m
n.q = g
e.q = j
assert m.q.q.q.u.q.txt == "g"