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

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

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

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

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

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

e.x = j
e.v = b
j.p = d
i.p = h
h.x = j
h.v = j
b.p = h
n.p = h
f.p = e
d.x = n
d.v = b
assert d.x.p.x.p.x.txt == "n"