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

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

h = A("h")
g = B("g")
i = B("i")
k = A("k")
e = A("e")

h.v = i
h.o = g
g.p = h
i.p = e
k.v = i
k.o = g
e.v = i
e.o = i
assert i.p.o.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.o: B = None
        self.txt = txt

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

h = A("h")
g = B("g")
i = B("i")
k = A("k")
e = A("e")

h.v = i
h.o = g
g.p = h
i.p = e
k.v = i
k.o = g
e.v = i
e.o = i
assert i.p.o.p.v.txt == "i"