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

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

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

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

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

c.p = d
c.v = b
e.s = c
e.t = c
e.p = b
d.x = c
i.t = g
i.r = g
i.o = e
g.t = i
g.r = i
g.o = e
b.s = c
b.t = c
b.p = e
a.x = c
assert d.x.v.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.v: B = None
        self.txt = txt

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

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

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

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

c.p = d
c.v = b
e.s = c
e.t = c
e.p = b
d.x = c
i.t = g
i.r = g
i.o = e
g.t = i
g.r = i
g.o = e
b.s = c
b.t = c
b.p = e
a.x = c
assert d.x.v.p.p.txt == "b"