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

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

a = A("a")
e = B("e")
j = B("j")
k = B("k")
h = A("h")
c = B("c")

a.v = h
a.w = j
e.o = a
j.o = h
k.o = h
h.v = a
h.w = k
c.o = a
assert e.o.w.o.w.o.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.w: B = None
        self.txt = txt

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

a = A("a")
e = B("e")
j = B("j")
k = B("k")
h = A("h")
c = B("c")

a.v = h
a.w = j
e.o = a
j.o = h
k.o = h
h.v = a
h.w = k
c.o = a
assert e.o.w.o.w.o.txt == "h"