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

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

g = A("g")
i = B("i")
h = A("h")

g.w = h
i.o = h
i.r = g
h.w = g
assert g.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

g = A("g")
i = B("i")
h = A("h")

g.w = h
i.o = h
i.r = g
h.w = g
assert g.w.w.w.txt == "h"