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

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

f = A("f")
a = B("a")
k = A("k")
l = B("l")
m = B("m")

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

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

f = A("f")
a = B("a")
k = A("k")
l = B("l")
m = B("m")

f.r = a
f.q = m
a.y = f
a.u = k
k.r = a
k.q = a
l.y = f
l.u = k
m.y = f
m.u = k
assert m.y.q.u.txt == "k"