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

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

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

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

d = A("d")
n = B("n")
k = C("k")
g = D("g")
f = B("f")

d.t = k
d.q = k
n.v = f
n.s = d
k.o = g
g.r = n
g.p = k
f.v = n
f.s = d
assert g.p.o.r.v.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.q: C = None
        self.txt = txt

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

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

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

d = A("d")
n = B("n")
k = C("k")
g = D("g")
f = B("f")

d.t = k
d.q = k
n.v = f
n.s = d
k.o = g
g.r = n
g.p = k
f.v = n
f.s = d
assert g.p.o.r.v.txt == "f"