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

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

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

c = A("c")
a = B("a")
d = C("d")
i = C("i")
m = B("m")
f = A("f")
g = C("g")
k = B("k")

c.p = m
c.r = m
a.q = g
a.t = i
d.x = g
i.x = d
m.q = d
m.t = g
f.p = a
f.r = m
g.x = d
k.q = d
k.t = g
assert g.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.r: B = None
        self.txt = txt

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

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

c = A("c")
a = B("a")
d = C("d")
i = C("i")
m = B("m")
f = A("f")
g = C("g")
k = B("k")

c.p = m
c.r = m
a.q = g
a.t = i
d.x = g
i.x = d
m.q = d
m.t = g
f.p = a
f.r = m
g.x = d
k.q = d
k.t = g
assert g.x.x.x.x.txt == "g"