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

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

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

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

b = A("b")
g = B("g")
m = C("m")
f = D("f")
e = A("e")

b.r = f
g.o = e
g.z = e
g.p = f
m.x = f
m.z = b
f.y = e
f.s = b
f.v = g
f.r = g
e.r = f
assert b.r.r.p.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

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

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

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

b = A("b")
g = B("g")
m = C("m")
f = D("f")
e = A("e")

b.r = f
g.o = e
g.z = e
g.p = f
m.x = f
m.z = b
f.y = e
f.s = b
f.v = g
f.r = g
e.r = f
assert b.r.r.p.s.r.txt == "f"