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

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

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

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

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

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

k.o = d
k.w = h
g.r = d
g.z = h
h.r = d
h.z = g
d.o = k
d.w = h
assert d.o.o.w.z.txt == "g"