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

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

d = A("d")
i = B("i")
n = B("n")
m = A("m")
c = A("c")
g = B("g")
h = A("h")
j = A("j")

d.z = h
d.o = i
i.v = g
n.v = i
m.z = c
m.o = n
c.z = m
c.o = n
g.v = n
h.z = d
h.o = i
j.z = c
j.o = i
assert j.o.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.o: B = None
        self.txt = txt

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

d = A("d")
i = B("i")
n = B("n")
m = A("m")
c = A("c")
g = B("g")
h = A("h")
j = A("j")

d.z = h
d.o = i
i.v = g
n.v = i
m.z = c
m.o = n
c.z = m
c.o = n
g.v = n
h.z = d
h.o = i
j.z = c
j.o = i
assert j.o.v.v.txt == "n"