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

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

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

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

i = A("i")
f = B("f")
d = C("d")
b = D("b")

i.y = f
f.t = i
d.w = f
b.p = f
b.s = d
assert i.y.t.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

i = A("i")
f = B("f")
d = C("d")
b = D("b")

i.y = f
f.t = i
d.w = f
b.p = f
b.s = d
assert i.y.t.y.txt == "f"