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

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

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

h.x = j
h.r = b
j.o = g
b.x = g
b.r = h
g.o = j
assert j.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.r: A = None
        self.txt = txt

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

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

h.x = j
h.r = b
j.o = g
b.x = g
b.r = h
g.o = j
assert j.o.o.o.txt == "g"