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

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

d = A("d")
i = B("i")
c = A("c")
m = B("m")

d.v = i
i.p = c
i.t = c
c.v = m
m.p = c
m.t = c
assert i.t.v.t.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

d = A("d")
i = B("i")
c = A("c")
m = B("m")

d.v = i
i.p = c
i.t = c
c.v = m
m.p = c
m.t = c
assert i.t.v.t.v.txt == "m"