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

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

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

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

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

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

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