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

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

h = A("h")
i = B("i")
c = B("c")
m = B("m")
f = A("f")

h.r = f
h.u = f
i.x = f
i.t = c
c.x = f
c.t = m
m.x = h
m.t = i
f.r = h
f.u = h
assert f.r.r.r.r.u.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.u: A = None
        self.txt = txt

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

h = A("h")
i = B("i")
c = B("c")
m = B("m")
f = A("f")

h.r = f
h.u = f
i.x = f
i.t = c
c.x = f
c.t = m
m.x = h
m.t = i
f.r = h
f.u = h
assert f.r.r.r.r.u.txt == "h"