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

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

m = A("m")
c = B("c")
k = A("k")
l = B("l")

m.y = l
m.u = k
c.u = k
c.q = m
k.y = c
k.u = m
l.u = m
l.q = k
assert k.y.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.u: A = None
        self.txt = txt

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

m = A("m")
c = B("c")
k = A("k")
l = B("l")

m.y = l
m.u = k
c.u = k
c.q = m
k.y = c
k.u = m
l.u = m
l.q = k
assert k.y.u.u.txt == "m"