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

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

f = A("f")
b = B("b")
h = A("h")
d = B("d")
m = A("m")
j = A("j")

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

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

f = A("f")
b = B("b")
h = A("h")
d = B("d")
m = A("m")
j = A("j")

f.p = d
f.v = d
b.x = d
h.p = d
h.v = d
d.x = b
m.p = b
m.v = b
j.p = d
j.v = d
assert j.p.x.x.x.x.txt == "d"