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

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

f = A("f")
h = B("h")
i = B("i")
k = A("k")

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

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

f = A("f")
h = B("h")
i = B("i")
k = A("k")

f.x = h
f.r = i
h.u = i
i.u = h
k.x = i
k.r = h
assert f.r.u.u.u.txt == "h"