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

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

k = A("k")
b = B("b")
h = A("h")
j = A("j")
m = A("m")
c = B("c")
d = A("d")
i = A("i")
f = B("f")

k.x = m
k.y = f
b.o = c
h.x = d
h.y = b
j.x = h
j.y = f
m.x = j
m.y = b
c.o = b
d.x = j
d.y = b
i.x = k
i.y = c
f.o = c
assert f.o.o.o.o.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.y: B = None
        self.txt = txt

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

k = A("k")
b = B("b")
h = A("h")
j = A("j")
m = A("m")
c = B("c")
d = A("d")
i = A("i")
f = B("f")

k.x = m
k.y = f
b.o = c
h.x = d
h.y = b
j.x = h
j.y = f
m.x = j
m.y = b
c.o = b
d.x = j
d.y = b
i.x = k
i.y = c
f.o = c
assert f.o.o.o.o.o.o.o.o.o.txt == "c"