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

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

d = A("d")
i = B("i")
l = A("l")
c = A("c")
j = A("j")
f = B("f")

d.p = c
i.p = f
i.w = j
l.p = c
c.p = d
j.p = c
f.p = i
f.w = d
assert i.p.w.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

d = A("d")
i = B("i")
l = A("l")
c = A("c")
j = A("j")
f = B("f")

d.p = c
i.p = f
i.w = j
l.p = c
c.p = d
j.p = c
f.p = i
f.w = d
assert i.p.w.p.p.txt == "d"