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

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

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

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

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

k.y = g
a.q = g
a.v = g
a.z = k
c.y = k
c.z = g
c.r = f
f.x = a
g.y = k
g.z = c
g.r = f
assert f.x.z.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

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

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

k.y = g
a.q = g
a.v = g
a.z = k
c.y = k
c.z = g
c.r = f
f.x = a
g.y = k
g.z = c
g.r = f
assert f.x.z.y.y.txt == "k"