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

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

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

class D:
    def __init__(self, txt: str):
        self.z: A = None
        self.o: C = None
        self.txt = txt

b = A("b")
j = B("j")
f = C("f")
g = D("g")
i = C("i")

b.y = g
b.p = f
j.z = b
j.v = i
f.p = i
f.x = j
g.z = b
g.o = i
i.p = f
i.x = j
assert i.p.p.p.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.p: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.z: A = None
        self.o: C = None
        self.txt = txt

b = A("b")
j = B("j")
f = C("f")
g = D("g")
i = C("i")

b.y = g
b.p = f
j.z = b
j.v = i
f.p = i
f.x = j
g.z = b
g.o = i
i.p = f
i.x = j
assert i.p.p.p.p.x.txt == "j"