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

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

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

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

c = A("c")
j = B("j")
h = C("h")
f = D("f")
d = B("d")
b = B("b")
g = B("g")
a = D("a")

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

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

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

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

c = A("c")
j = B("j")
h = C("h")
f = D("f")
d = B("d")
b = B("b")
g = B("g")
a = D("a")

c.p = b
c.r = h
j.p = c
j.v = g
h.t = b
f.r = c
f.p = a
f.o = a
f.x = j
d.p = c
d.v = b
b.p = c
b.v = g
g.p = c
g.v = b
a.r = c
a.p = f
a.o = f
a.x = j
assert c.p.p.p.v.txt == "g"