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

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

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

g.x = k
k.q = g
k.x = l
l.x = k
assert k.q.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

g.x = k
k.q = g
k.x = l
l.x = k
assert k.q.x.x.txt == "l"