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

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

f = A("f")
d = B("d")
a = B("a")
j = A("j")
i = A("i")
k = B("k")
b = A("b")

f.v = j
d.p = a
a.p = d
j.v = i
i.v = b
k.p = a
b.v = i
assert b.v.v.v.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

f = A("f")
d = B("d")
a = B("a")
j = A("j")
i = A("i")
k = B("k")
b = A("b")

f.v = j
d.p = a
a.p = d
j.v = i
i.v = b
k.p = a
b.v = i
assert b.v.v.v.v.v.v.v.txt == "i"