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

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

j = A("j")
b = B("b")
e = B("e")
c = A("c")
k = A("k")
h = B("h")
f = B("f")
d = B("d")
g = B("g")

j.o = c
b.z = c
e.z = c
c.o = k
k.o = c
h.z = c
f.z = j
d.z = j
g.z = c
assert d.z.o.o.o.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

j = A("j")
b = B("b")
e = B("e")
c = A("c")
k = A("k")
h = B("h")
f = B("f")
d = B("d")
g = B("g")

j.o = c
b.z = c
e.z = c
c.o = k
k.o = c
h.z = c
f.z = j
d.z = j
g.z = c
assert d.z.o.o.o.o.o.o.o.o.txt == "k"