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

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

j = A("j")
n = B("n")
m = A("m")
l = B("l")

j.q = m
n.w = j
m.q = j
l.w = j
assert n.w.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

j = A("j")
n = B("n")
m = A("m")
l = B("l")

j.q = m
n.w = j
m.q = j
l.w = j
assert n.w.q.q.q.txt == "m"