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.txt = txt

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

c.o = g
k.q = c
g.q = c
assert k.q.o.q.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.txt = txt

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

c.o = g
k.q = c
g.q = c
assert k.q.o.q.txt == "c"