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

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

a = A("a")
c = B("c")
i = B("i")
j = A("j")
f = A("f")

a.r = c
a.y = i
c.x = i
i.x = c
j.r = c
j.y = c
f.r = i
f.y = i
assert j.y.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.y: B = None
        self.txt = txt

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

a = A("a")
c = B("c")
i = B("i")
j = A("j")
f = A("f")

a.r = c
a.y = i
c.x = i
i.x = c
j.r = c
j.y = c
f.r = i
f.y = i
assert j.y.x.x.txt == "c"