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

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

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

g = A("g")
d = B("d")
i = C("i")
f = A("f")
c = C("c")
n = A("n")
j = B("j")
m = A("m")

g.t = c
d.x = i
d.p = c
i.q = d
f.t = i
c.q = j
n.t = c
j.x = c
j.p = c
m.t = c
assert i.q.x.q.p.q.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

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

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

g = A("g")
d = B("d")
i = C("i")
f = A("f")
c = C("c")
n = A("n")
j = B("j")
m = A("m")

g.t = c
d.x = i
d.p = c
i.q = d
f.t = i
c.q = j
n.t = c
j.x = c
j.p = c
m.t = c
assert i.q.x.q.p.q.x.q.txt == "j"