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

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

k = A("k")
f = B("f")
h = A("h")
g = B("g")

k.y = f
k.o = g
f.w = k
h.y = g
h.o = g
g.w = h
assert k.o.w.o.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.o: B = None
        self.txt = txt

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

k = A("k")
f = B("f")
h = A("h")
g = B("g")

k.y = f
k.o = g
f.w = k
h.y = g
h.o = g
g.w = h
assert k.o.w.o.txt == "g"