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

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

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

d.s = j
d.o = k
j.w = d
k.s = h
k.o = d
h.w = d
assert d.o.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.o: A = None
        self.txt = txt

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

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

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