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

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

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

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

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

f.y = b
f.v = e
f.z = e
e.y = c
b.r = f
c.v = b
c.s = f
g.v = b
g.s = f
assert e.y.v.r.v.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.v: B = None
        self.z: B = None
        self.txt = txt

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

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

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

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

f.y = b
f.v = e
f.z = e
e.y = c
b.r = f
c.v = b
c.s = f
g.v = b
g.s = f
assert e.y.v.r.v.y.txt == "c"