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

class B:
    def __init__(self, txt: str):
        self.w: D = None
        self.t: D = None
        self.u: D = None
        self.p: A = None
        self.txt = txt

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

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

d = A("d")
e = B("e")
b = C("b")
a = D("a")
g = D("g")
k = A("k")
c = A("c")

d.v = k
e.w = g
e.u = g
e.t = a
e.p = c
b.t = g
b.w = d
a.r = e
a.o = g
g.r = e
g.o = a
k.v = d
c.v = k
assert e.p.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.w: D = None
        self.t: D = None
        self.u: D = None
        self.p: A = None
        self.txt = txt

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

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

d = A("d")
e = B("e")
b = C("b")
a = D("a")
g = D("g")
k = A("k")
c = A("c")

d.v = k
e.w = g
e.u = g
e.t = a
e.p = c
b.t = g
b.w = d
a.r = e
a.o = g
g.r = e
g.o = a
k.v = d
c.v = k
assert e.p.v.v.txt == "d"