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

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

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

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

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

e.r = d
e.x = g
n.p = k
n.v = d
d.q = e
k.w = e
k.r = e
k.x = d
g.p = k
g.v = d
assert n.v.q.r.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.x: B = None
        self.txt = txt

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

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

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

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

e.r = d
e.x = g
n.p = k
n.v = d
d.q = e
k.w = e
k.r = e
k.x = d
g.p = k
g.v = d
assert n.v.q.r.q.r.txt == "d"