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

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

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

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

g = A("g")
a = B("a")
f = C("f")
h = D("h")

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

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

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

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

g = A("g")
a = B("a")
f = C("f")
h = D("h")

g.w = f
a.p = f
f.y = g
h.p = g
h.t = g
assert f.y.w.y.w.txt == "f"