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

d = A("d")
j = B("j")
h = A("h")

d.w = h
j.o = h
h.w = d
assert d.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.txt = txt

d = A("d")
j = B("j")
h = A("h")

d.w = h
j.o = h
h.w = d
assert d.w.w.w.txt == "h"