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

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

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

h.v = k
m.p = h
m.x = d
k.p = h
k.x = d
f.v = m
e.v = k
i.v = m
c.v = m
d.v = m
assert i.v.x.v.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

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

h.v = k
m.p = h
m.x = d
k.p = h
k.x = d
f.v = m
e.v = k
i.v = m
c.v = m
d.v = m
assert i.v.x.v.p.v.txt == "k"