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

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

h = A("h")
l = B("l")
a = B("a")
d = B("d")
k = B("k")
f = B("f")
c = B("c")
j = A("j")

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

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

h = A("h")
l = B("l")
a = B("a")
d = B("d")
k = B("k")
f = B("f")
c = B("c")
j = A("j")

h.z = a
l.w = f
l.o = j
a.w = l
a.o = h
d.w = a
d.o = j
k.w = c
k.o = j
f.w = l
f.o = h
c.w = f
c.o = h
j.z = l
assert j.z.o.z.o.z.w.txt == "f"