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

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

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

class D:
    def __init__(self, txt: str):
        self.x: C = None
        self.q: B = None
        self.o: A = None
        self.u: B = None
        self.txt = txt

g = A("g")
m = B("m")
f = C("f")
a = D("a")
i = B("i")
j = C("j")

g.r = a
m.v = g
m.q = a
f.r = a
f.p = g
f.y = g
f.o = g
a.x = f
a.q = i
a.u = i
a.o = g
i.v = g
i.q = a
j.r = a
j.p = g
j.y = g
j.o = g
assert g.r.u.v.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.x: C = None
        self.q: B = None
        self.o: A = None
        self.u: B = None
        self.txt = txt

g = A("g")
m = B("m")
f = C("f")
a = D("a")
i = B("i")
j = C("j")

g.r = a
m.v = g
m.q = a
f.r = a
f.p = g
f.y = g
f.o = g
a.x = f
a.q = i
a.u = i
a.o = g
i.v = g
i.q = a
j.r = a
j.p = g
j.y = g
j.o = g
assert g.r.u.v.txt == "g"