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

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

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

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

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

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

d.p = i
m.t = f
m.s = i
c.t = f
c.s = g
f.t = m
f.s = i
l.t = m
l.s = n
n.p = d
i.p = d
g.p = d
assert g.p.p.p.p.p.p.txt == "i"