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

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

h = A("h")
a = B("a")
l = A("l")
n = B("n")
k = B("k")
f = B("f")
m = A("m")

h.r = m
h.t = m
a.p = l
a.q = h
l.r = h
l.t = h
n.p = h
n.q = h
k.p = m
k.q = m
f.p = m
f.q = m
m.r = h
m.t = l
assert m.t.r.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.t: A = None
        self.txt = txt

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

h = A("h")
a = B("a")
l = A("l")
n = B("n")
k = B("k")
f = B("f")
m = A("m")

h.r = m
h.t = m
a.p = l
a.q = h
l.r = h
l.t = h
n.p = h
n.q = h
k.p = m
k.q = m
f.p = m
f.q = m
m.r = h
m.t = l
assert m.t.r.t.t.t.txt == "h"