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

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

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

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

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

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

h.x = b
e.o = f
g.x = n
j.x = n
c.o = d
n.o = f
d.x = n
f.x = b
i.x = c
b.o = g
assert h.x.o.x.o.x.o.txt == "g"