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

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

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

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

g = A("g")
c = B("c")
m = C("m")
f = D("f")
d = A("d")
h = A("h")

g.w = m
c.p = g
c.w = f
m.y = c
f.p = c
d.w = m
h.w = m
assert f.p.p.w.y.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

g = A("g")
c = B("c")
m = C("m")
f = D("f")
d = A("d")
h = A("h")

g.w = m
c.p = g
c.w = f
m.y = c
f.p = c
d.w = m
h.w = m
assert f.p.p.w.y.txt == "c"