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

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

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

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

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

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

l.o = k
k.q = l
k.r = g
g.q = l
g.r = k
assert l.o.q.o.txt == "k"