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

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

l = A("l")
a = B("a")
k = B("k")
j = A("j")

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

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

l = A("l")
a = B("a")
k = B("k")
j = A("j")

l.z = j
l.r = a
a.u = l
a.q = k
k.u = j
k.q = a
j.z = l
j.r = a
assert a.u.z.z.txt == "l"