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

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

k = A("k")
j = B("j")
d = A("d")
f = A("f")
e = B("e")
m = A("m")

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

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

k = A("k")
j = B("j")
d = A("d")
f = A("f")
e = B("e")
m = A("m")

k.v = j
j.x = f
j.p = e
d.v = e
f.v = e
e.x = f
e.p = j
m.v = e
assert j.x.v.p.p.txt == "e"