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

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

c = A("c")
j = B("j")
n = A("n")
g = A("g")
f = B("f")
h = A("h")
m = A("m")
l = B("l")
e = B("e")

c.r = h
c.s = h
j.q = l
j.p = e
n.r = m
n.s = h
g.r = c
g.s = c
f.q = l
f.p = e
h.r = m
h.s = c
m.r = n
m.s = c
l.q = e
l.p = e
e.q = f
e.p = f
assert f.p.q.p.p.q.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.s: A = None
        self.txt = txt

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

c = A("c")
j = B("j")
n = A("n")
g = A("g")
f = B("f")
h = A("h")
m = A("m")
l = B("l")
e = B("e")

c.r = h
c.s = h
j.q = l
j.p = e
n.r = m
n.s = h
g.r = c
g.s = c
f.q = l
f.p = e
h.r = m
h.s = c
m.r = n
m.s = c
l.q = e
l.p = e
e.q = f
e.p = f
assert f.p.q.p.p.q.p.p.txt == "f"