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

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

m = A("m")
f = B("f")
a = B("a")
i = B("i")
g = A("g")
h = A("h")
j = B("j")
d = B("d")
e = B("e")

m.x = g
f.t = e
f.r = e
a.t = d
a.r = d
i.t = a
i.r = e
g.x = m
h.x = g
j.t = d
j.r = e
d.t = j
d.r = e
e.t = a
e.r = f
assert g.x.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

m = A("m")
f = B("f")
a = B("a")
i = B("i")
g = A("g")
h = A("h")
j = B("j")
d = B("d")
e = B("e")

m.x = g
f.t = e
f.r = e
a.t = d
a.r = d
i.t = a
i.r = e
g.x = m
h.x = g
j.t = d
j.r = e
d.t = j
d.r = e
e.t = a
e.r = f
assert g.x.x.x.x.x.x.txt == "g"