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

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

m = A("m")
j = B("j")
g = A("g")
b = B("b")

m.o = g
j.t = g
g.o = m
b.t = g
assert g.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

m = A("m")
j = B("j")
g = A("g")
b = B("b")

m.o = g
j.t = g
g.o = m
b.t = g
assert g.o.o.o.o.txt == "g"