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

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

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

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

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

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

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

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

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

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

a.r = b
a.u = b
a.s = f
a.y = g
f.y = b
b.p = a
g.s = f
g.v = b
c.y = b
assert f.y.p.s.y.p.txt == "a"