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

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

d = A("d")
h = B("h")
k = B("k")
c = B("c")

d.v = h
d.w = c
h.p = c
k.p = c
c.p = k
assert k.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.w: B = None
        self.txt = txt

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

d = A("d")
h = B("h")
k = B("k")
c = B("c")

d.v = h
d.w = c
h.p = c
k.p = c
c.p = k
assert k.p.p.p.txt == "c"