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

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

m = A("m")
g = B("g")
e = A("e")
k = B("k")

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

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

m = A("m")
g = B("g")
e = A("e")
k = B("k")

m.r = g
g.o = m
g.q = k
e.r = k
k.o = e
k.q = g
assert m.r.o.r.txt == "g"