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

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

i = A("i")
f = B("f")
l = B("l")
e = A("e")
a = A("a")
b = B("b")
h = A("h")

i.o = l
i.z = e
f.p = h
l.p = a
e.o = b
e.z = h
a.o = f
a.z = i
b.p = e
h.o = f
h.z = e
assert l.p.o.p.o.p.z.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.z: A = None
        self.txt = txt

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

i = A("i")
f = B("f")
l = B("l")
e = A("e")
a = A("a")
b = B("b")
h = A("h")

i.o = l
i.z = e
f.p = h
l.p = a
e.o = b
e.z = h
a.o = f
a.z = i
b.p = e
h.o = f
h.z = e
assert l.p.o.p.o.p.z.o.txt == "b"