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

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

k = A("k")
d = B("d")
c = A("c")
i = B("i")

k.u = i
k.w = c
d.o = c
c.u = d
c.w = k
i.o = k
assert k.u.o.u.o.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.w: A = None
        self.txt = txt

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

k = A("k")
d = B("d")
c = A("c")
i = B("i")

k.u = i
k.w = c
d.o = c
c.u = d
c.w = k
i.o = k
assert k.u.o.u.o.txt == "k"