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.q: A = None
        self.txt = txt

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

l.y = a
l.u = k
a.q = k
k.y = a
k.u = l
g.q = l
assert k.y.q.y.q.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.q: A = None
        self.txt = txt

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

l.y = a
l.u = k
a.q = k
k.y = a
k.u = l
g.q = l
assert k.y.q.y.q.txt == "k"