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

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

a = A("a")
n = B("n")
m = B("m")
h = B("h")
f = A("f")
k = B("k")

a.v = f
n.x = k
n.o = m
m.x = n
m.o = n
h.x = m
h.o = m
f.v = a
k.x = n
k.o = n
assert k.x.x.o.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

a = A("a")
n = B("n")
m = B("m")
h = B("h")
f = A("f")
k = B("k")

a.v = f
n.x = k
n.o = m
m.x = n
m.o = n
h.x = m
h.o = m
f.v = a
k.x = n
k.o = n
assert k.x.x.o.txt == "n"