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

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

d = A("d")
h = B("h")
k = B("k")
a = A("a")
b = B("b")

d.y = a
d.w = k
h.q = b
h.o = a
k.q = h
k.o = d
a.y = d
a.w = h
b.q = k
b.o = d
assert a.y.w.q.q.o.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.w: B = None
        self.txt = txt

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

d = A("d")
h = B("h")
k = B("k")
a = A("a")
b = B("b")

d.y = a
d.w = k
h.q = b
h.o = a
k.q = h
k.o = d
a.y = d
a.w = h
b.q = k
b.o = d
assert a.y.w.q.q.o.txt == "d"